Register
It is currently Sat Aug 30, 2014 12:22 am

ssh/background process--script not behaving as expected


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Sun Sep 30, 2012 10:48 am   

Joined: Sun Sep 30, 2012 10:34 am
Posts: 3
Trying to get a script together to automate updates across several hundred systems. The main goal is for the script to kick off the update process........then continue on without waiting for the update process to finish. The portion in red is where my problem lies.

If I use /usr/bin/yum -y update &......the system skips that line and goes right to the last echo. Now, if I use ssh -fn instead of the -t, it complains about sudo needing a tty. If I use ssh -ft, it will let it start in the background.........but it clobbers the echo and still waits to move to the next host in the file. I think what I need is to somehow detach the yum -y update as a seperate process but I'm not entirely sure how to do this.

Here's a snip of the script:

#!/bin/bash
for i in `cat hostlist`; do ssh -t $i 'if sudo /usr/bin/yum
check-update > /dev/null 2>&1;

then echo $HOSTNAME:`date +%m%d%y`:Updated;
else
`(sudo /usr/bin/yum -y update & > /dev/null 2>&1)`

echo $HOSTNAME:`date +%m%d%y`:Updates Required;
fi';
done >> updated.out


Top
 Profile  
 PostPosted: Tue Oct 02, 2012 4:20 pm   
User avatar

Joined: Fri Jul 22, 2011 5:39 pm
Posts: 47
What happens if "yum -y update" is run on a yum-centric host and there are no updates?
Wouldn't update run and exit 0 if there are no updates?

If yes, maybe you could just run "yum -y update" and skip the check-updates routine?
...


Top
 Profile WWW  
 PostPosted: Thu Oct 04, 2012 7:33 am   

Joined: Sun Sep 30, 2012 10:34 am
Posts: 3
Habitual wrote:
What happens if "yum -y update" is run on a yum-centric host and there are no updates?
Wouldn't update run and exit 0 if there are no updates?

If yes, maybe you could just run "yum -y update" and skip the check-updates routine?
...


Still have the same problem. The main thing is........I need the script to kick of yum -y update in the background, and continue onto the next host in the script. Seems to be an issue with how ssh behaves.


Top
 Profile  
 PostPosted: Thu Oct 04, 2012 1:13 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
hi,

I'd say to try to use `disown'.
that should remove sudo from the current shell
maybe it could be used inside the sudo command, but the sudo might remain.


Top
 Profile  
 PostPosted: Fri Oct 05, 2012 7:56 pm   

Joined: Mon Sep 24, 2012 7:48 am
Posts: 5
"several hundred systems"?
Holy cow!
Do you type in the password for each? If not, how do you avoid it?

This looks like a job for cron--instead of launching the process remotely, let cron run as root on each host and do the update in the wee hours.

BTW, you don't need sudo to run "yum check-update". It doesn't change the system, so any user can do it. The only downside is that the current-file data gets downloaded for both the user and later for root when the actual update is done, so it's a little less efficient.


Top
 Profile  
 PostPosted: Sat Oct 06, 2012 10:32 am   

Joined: Sun Sep 30, 2012 10:34 am
Posts: 3
KenJackson wrote:
"several hundred systems"?
Holy cow!
Do you type in the password for each? If not, how do you avoid it?

This looks like a job for cron--instead of launching the process remotely, let cron run as root on each host and do the update in the wee hours.

BTW, you don't need sudo to run "yum check-update". It doesn't change the system, so any user can do it. The only downside is that the current-file data gets downloaded for both the user and later for root when the actual update is done, so it's a little less efficient.


ssh keys of course........and with the security changes to our systems.......all yum commands have to be run with sudo or as root. Very limited environment..........cron and at are not options. Heck, if my life was going to be that simple.........I'd just have scheduled check ins to the sattelite server......alas my constraints are what they are;-)

I'm using disown.......which "sooooortttttt" of works. If I kill the ssh session, it will keep the update going in the background.......however the script won't kick off the update, then continue to the next system. It still waits until the update process finishes before moving to the next host. Now, I ctrl-c..........it will disconnect from the current system, move to the next.....and the update will continue to run on the previous system......but I don't want to sit there and ctrl-c each connection......kind of defeats the purpose.


Top
 Profile  
 PostPosted: Mon Oct 08, 2012 7:35 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Yarg,

Maybe instead of running the commands over ssh you scp up a temp script of the commands and run that.

Also if one can take out the requirement to sudo by using a root ssh key I suspect that would help. Of course your environment's restrictions may not give you this option.

I like the tool 'onall' for admin of remote servers using ssh, it's GPL;
https://code.google.com/p/code-ticketma ... wiki/Onall

DW


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP