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
LinuxLinux OS Dev

Avatar of undefined
Last Comment
woolmilkporc

8/22/2022 - Mon
farzanj

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.
omarfarid

What is needed?
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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
farzanj

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.
oo_tatang

ASKER
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.
omarfarid

Can you run it as below to see what is happening?

bash -x scriptname

this should show you where it is failing
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
woolmilkporc

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Julian Parker

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
woolmilkporc

What is your reason for giving grade "B"?