Link to home
Start Free TrialLog in
Avatar of oo_tatang

asked on

Please help modify thi linux script

while read server
  echo -n $server
  ssh root@$server "sed -i '/.*ctrlaltdel.*/ s/^/#/' /etc/inittab"

  if [ $? -ne 0 ]; then
    echo "[ FAIL ]"
    echo "[ done ]"
done < tone_dev

ca::ctrlaltdel:/sbin/shutdown -t3 -r now
#ca::ctrlaltdel:/sbin/shutdown -t3 -r now

[root@server07 scripts]# ./[ done ]
Avatar of farzanj
Flag of Canada image

What is wrong?  What do you need?

From other question it seems you have looping issue.  So make sure you have all server names in the tone_dev file, one per line.

Also try putting the full path of tone_dev file.
What is needed?
Avatar of oo_tatang



As you can see, it does not loop. It just modified the first server1 and it did not proceed to the rest of the servers in the file. Please see below the out after executing the scripts

[root@server07 scripts]# ./[ done ]

the contents of tone_dev
There's nothing wrong with this script just like there was nothing wrong with my previous solution but for some reason beyond my comprehension, it did not work for you and strangely enough an equivalent syntax of it by someone else worked.  In particular it has a while loop and you are redirecting as well, so it should work unless something else is wrong, like server2 is unreachable or may be even stranger.
The script seems to be editing the server1. it does not edit the /etc/inittab in server2 , server3 and so on... All the servers are up and running. The looping just stops at server1 . Please help. There should be something still needed in the script.
Can you run it as below to see what is happening?

bash -x scriptname

this should show you where it is failing
Avatar of woolmilkporc
Flag of Germany image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
can you ssh to each of the servers without getting a prompt?
Are all the servers contactable using the hostname?

bash -x (as per omarfarid's reponse) will show you more info
What is your reason for giving grade "B"?