Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

BASH Question

  • 06-04-2009 6:56pm
    #1
    Registered Users, Registered Users 2 Posts: 1,227 ✭✭✭


    Hi Guys,

    Here is my problem. I spend alot of my day using BASH. I want to keep an archive of what I've typed so that I can look back at previous work i've done in the event of a problem occurring.

    By editing my .bashrc file I added script -a /home/steve/System/history/`date +%F`

    This command does pretty much what I want but it is limited to my local machine. This is because bash will use the .profile on the foreign machine.Most of the day I ssh into other machines and I want this logged aswell.

    Has anyone any suggestions?

    /Steve


Comments

  • Registered Users, Registered Users 2 Posts: 354 ✭✭AndrewMc


    If you want the log file stored on the remote machine, have you tried something like:

    ssh somewhere "script -a logfile"
    ?


  • Registered Users, Registered Users 2 Posts: 1,227 ✭✭✭stereo_steve


    Thanks Andrew but I want all logs on my local machine. Thats the problem. I can't think of a way to do it.


  • Registered Users, Registered Users 2 Posts: 2,426 ✭✭✭ressem


    Can you set and point the bash environmental variable HISTFILE to a mounted network share on the remote machines?


  • Registered Users, Registered Users 2 Posts: 1,606 ✭✭✭djmarkus


    Putty can do session logging, one of my old workmates used this alot to CYA

    Before any says it, there is a linux version of putty.

    EDIT

    Actually SSH can do this using tee:

    ssh 192.168.1.254 | tee -a logfile

    Your session will be saved in logfile, word of warning though, you get all the terminal escape sequences.


  • Registered Users, Registered Users 2 Posts: 1,227 ✭✭✭stereo_steve


    Thanks Guys,

    I think ssh 192.168.1.254 | tee -a logfile is the winner for me. I'll setp up so that every time I ssh now it is logged . Thanks

    /Steve


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,755 ✭✭✭niallb


    Hi,
    interesting discussion. I'd often have a need for similar records
    and I've had an idea that might work well for you.
    If you give it a go, let me know how you get on.

    Reading this made me add a logging section to my ~/.screenrc
    to see could I automate something approaching what you describe.
    I use screen a lot, as I often need to leave processes running, and
    reconnect from different locations.
    #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=
    # startup_message off		# Turn this off when you've read it.
    
    logtstamp on			# Turn logging of timestamp on
    logtstamp after 180		# At 3 minute intervals
    
    
    deflog on			# Log windows by default
    logfile log-%Y-%m-%d.%t.%n		# Logfile name log-DATESTAMP.TITLE.NUMBER
    
    
    screen -L -t Local		# Start one screen, with title Local
    #screen -L -t Mail mutt		# You can start many by listing programs
    
    hardstatus alwayslastline 	# This sets visible the statusbar defined below.
    hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= wK}%+Lw%< %{= KW}%-=%H: %d %M %c:%s%{-}'			# Format is in manpage
    #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=
    
    

    Copy these lines to the file ~/.screenrc on the machine
    you want to keep the logs on.
    Make a directory for your logs, change into it and execute screen
    You'll see a status bar on the bottom with a marker for your current session.
    It will be called Local and will be logged to a file called log.Local.0
    in the current directory.

    Screen allows you open multiple terminals in the one session.

    You can open windows manually, and give them a title with screen -t.
    My suggestion is when you want to open an ssh connection, you run it like this:
    screen -t remotehostname_or_taskdescription ssh remotename

    It'll pop open another window within the same terminal with the name given,
    and it'll also LOG all output from that to another file in the same directory
    with the name given. Try it and see what I mean. Used like this, it gives you
    per host logging, or the option of per task logging which is neat.
    (This directory is based on first screen launch - the session - so you can
    run the additional screen commands from wherever.)

    man screen for more detail, but basically CTRL-A is a command key,
    and there's a lot you can do with it.

    You can swap between open windows using CTRL-A A by default,
    but this can of course be changed if it interferes with any keys
    you need for other applications.
    You may well already be familiar with screen, but there are so many things you can make it do, that it's always worth going back to.

    You can background everything at any point by using CTRL-A D for detach.
    Then you can reconnect to it by connecting back to the machine (local or ssh)
    opening a terminal, and typing screen -D -RR . This reattaches, but will
    detach the session first if it's open elsewhere. It 's the easiest behaviour to grasp.
    I think this will also make it really easy to keep the logs on the one machine,
    and access the whole setup via an initial connection from another one.

    At risk of digressing, I'll mention that there's also an option which allows you share a session between a number of people, which I've used for teaching and shared admin tasks during major headaches. This is a -x option, and the manpage has more detail on it.
    I'll mention also that you can use screen as a direct connection to a serial port, so
    replacing minicom or whatever you're used to for serial comms - again remotely possible.
    Now I'll stop. Screen is the desktop environment for those who find pearls in shells.


Advertisement