Link to home
Start Free TrialLog in
Avatar of oo_tatang
oo_tatang

asked on

Please help modify thi linux script

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

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

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

[root@server07 scripts]# ./disable_ctrlaltdel.sh
server1.am.dev.company.net[ done ]


server1.am.dev.company.net
server2.am.dev.company.net
Avatar of farzanj
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
oo_tatang

ASKER

Guys,

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]# ./disable_ctrlaltdel.sh
server1.am.dev.company.net[ done ]

the contents of tone_dev

server1.am.dev.company.net
server2.am.dev.company.net
server3.am.dev.company.net
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
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
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"?