Results 1 to 7 of 7

Thread: SSH in a script question...

Hybrid View

  1. #1

    SSH in a script question...

    Hello, I have a MASSIVE backup script and the following lines are giving me fits... I am wanting to run 'df -hT' on the server, 'ls -lt' to list the timestamps of the directories present, and write this info to a logfile ON THE SERVER. Check this:

    Keep in Mind: LOGLOCATION4=~/, BUSUBDIR=a form of today's date (I forget what I actually used here)


    #Track used disk space
    ssh backups df -hT | grep /backups >> $LOGLOCATION4$BUSUBDIR.txt
    ssh backups echo ' ' >> $LOGLOCATION4$BUSUBDIR.txt

    #List timestamps
    ssh backups ls -lt $BUDEST/* >> $LOGLOCATION4$BUSUBDIR.txt
    ssh backups echo ' ' >> $LOGLOCATION4$BUSUBDIR.txt
    ssh backups ls -lt $BUDEST2/* >> $LOGLOCATION4$BUSUBDIR.txt
    ssh backups echo ' ' >> $LOGLOCATION4$BUSUBDIR.txt
    ssh backups ls -lt $BUDEST3/* >> $LOGLOCATION4$BUSUBDIR.txt

    #Email log to someone
    ssh backups cat $LOGLOCATION4$BUSUBDIR.txt | mail -r $FEMAIL -s 'Backup Server Space and Time Check' $TEMAIL

    What is happening is that the df/ls log is being written to the home directory on the LOCAL machine instead of on the server. Then when 'cat' tries to find the file to send it out, it reports that it doesn't exist. I have tried various combinations of quotes and stuff, but am having no luck... Any help would be greatly appreciated.
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    Code:
    #Track used disk space
    ssh backups 'df -hT | grep /backups >> $LOGLOCATION4$BUSUBDIR.txt'
    ssh backups 'echo  >> $LOGLOCATION4$BUSUBDIR.txt'
    #List timestamps
    ssh backups 'ls -lt $BUDEST/\* >> $LOGLOCATION4$BUSUBDIR.txt'
    ssh backups 'echo  >> $LOGLOCATION4$BUSUBDIR.txt'
    ssh backups 'ls -lt $BUDEST2/\* >> $LOGLOCATION4$BUSUBDIR.txt'
    ssh backups 'echo  >> $LOGLOCATION4$BUSUBDIR.txt'
    ssh backups 'ls -lt $BUDEST3/\* >> $LOGLOCATION4$BUSUBDIR.txt'
    
    #Email log to someone
    ssh backups 'cat $LOGLOCATION4$BUSUBDIR.txt | mail -r $FEMAIL -s \'Backup Server Space and Time Check\' $TEMAIL'
    Note the commands executed, when piping etc, needs to be parsed as a string, instead of as command followed by args.
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

  3. #3
    Ah haa... See, I have done commands over ssh before, and never used quotes, but they were simple commands that didn't use any piping or redirection. Thanks for the help. I will change this script, and try it when I get home tonight (hopefully). Now, if I can just get my rsync excludes to work, I will be in business!
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

  4. #4
    Okie dokie. I did have to change it a bit... On the diskspace and timestamp section, I had to use all " instead of '. That is one thing that ALWAYS trips me up... when to use " or ', AND when or not to escape them with '\'. The only thing I still can't get to work is the last line, where it 'cat's the logfile and is supposed to send it out. I get no errors, but I never receive the mail. I have tried running it directly on the server's command line, but it seems to be prompting me for something, with the only way out being ctrl+c or ctrl+d. At this point, it says "EOT" and exits. Beats me...
    In all though, the entire script works like a champ now, exactly as I want it to, with the exception of the mail. Thanks!
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

  5. #5
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    have you tried
    Code:
    ssh backups 'cat $LOGLOCATION4$BUSUBDIR.txt | mail -s \'Backup Server Space and Time Check\' $TEMAIL'
    Since I can't see what your -r $FEMAIL should do, and since the flag -r isn't mentioned supported in any way under mail(1)
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

  6. #6
    Well, I tried this and it still isn't working for me. It does the same thing (looking like it is waiting for a response from me until I ctrl+c or d it). I have the executables 'mail' and 'mailx' on my Suse 10.1 system, but when I go to the man pages (either man mail, or man mailx) I am shown the man page for something called 'nail'. In that man page, a '-r' is the from address, and when this mail line used to work (well, it worked as in, I received no errors, and the screen returned to a prompt instead of waiting for me to do something), I had to have the -r <from-address> specified, or else it would do what it is doing now. So strange... Maybe I need to look into pine or some other tool in an attempt to send this unattended...
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

Similar Threads

  1. Probs in a script called from another script
    By Outlaw in forum Programming
    Replies: 1
    Last Post: 03-12-2004, 02:54 PM
  2. Dummy shell script question
    By elovkoff in forum Programming
    Replies: 7
    Last Post: 03-19-2003, 04:15 PM
  3. Bash Script question....
    By gfunkmonk in forum Programming
    Replies: 6
    Last Post: 08-26-2002, 09:47 PM
  4. Gimp-->Script-Fu-->Logo Question?
    By gmoreno in forum Linux - General Topics
    Replies: 0
    Last Post: 08-25-2002, 05:57 PM
  5. linux/unix boot script question
    By morphman in forum Programming
    Replies: 4
    Last Post: 05-31-2002, 12:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •