Machine rebooting when shell script is killed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Machine rebooting when shell script is killed
# 1  
Old 12-08-2011
Machine rebooting when shell script is killed

I am trying to kill a shell script by grepping it, but the machine is being shutdown totally when i kill it

Below is the code
Code:
kill `ps -ef |grep test.sh| grep -v grep`
stat=$?
if [ $stat -eq 0 ] # check the return code
then
       echo "  script killed at $(date +%D@%T) "
else
       echo "  script process does not exists at $(date +%D@%T) " 
fi
done

Any inputs are appreciated....

Thank you
Moderator's Comments:
Mod Comment Please use

code tags!

Last edited by vbe; 12-08-2011 at 10:30 AM..
# 2  
Old 12-08-2011
Have you tried something like:
Code:
echo kill `ps -ef |grep test.sh| grep -v grep`

to see what arguments you are passing to kill.
Or even sh -x badscript?

If I would have to guess ... you are running this script as 'root' and test.sh's parent process is "1". So when you run you code, you are killing process 1.

Take a look at pgrep and pkill, they may give you the functionality you need.
This User Gave Thanks to m.d.ludwig For This Post:
# 3  
Old 12-08-2011
the way you are trying to kill is not correct!!

i have splitted your kill command and see what happens..

see what variable a holds in it ??
Code:
# a=`ps -ef |grep /usr/sbin/cron | grep -v grep`
# echo $a
root 438 1 0 Oct 20 2 g 0:02 /usr/sbin/cron

to kill a process you would need pid and just extract that..
Code:
kill `ps -ef |grep test.sh | grep -v grep | awk '{print $2}'`

and try to execute ps -ef |grep test.sh and check whether its searching for the correct file..
This User Gave Thanks to chidori For This Post:
# 4  
Old 12-08-2011
Code:
kill -9 `ps -ef | grep test.sh | grep -v grep | awk '{print $2}'`
stat=$?
if [ $stat -eq 0 ]
then
    echo "  script killed at $(date +%D@%T) "
else
    echo "  script process does not exists at $(date +%D@%T) " 
fi

This User Gave Thanks to balajesuri For This Post:
# 5  
Old 12-08-2011
What is the "done" for? Is this an extract from another script with a loop?
This User Gave Thanks to vbe For This Post:
# 6  
Old 12-08-2011
pgrep and pkill are not recognised on this machine, i am able to kill the script from terminal manually, but not from script

---------- Post updated at 10:48 AM ---------- Previous update was at 10:33 AM ----------

Thanks to all , SAVED me from a Heart attack.....

---------- Post updated at 11:47 AM ---------- Previous update was at 10:48 AM ----------

Quote:
Originally Posted by vbe
What is the "done" for? Is this an extract from another script with a loop?
Sorry about the code tags, how do i post code if i want to....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Rebooting Windows machine leads to continue sync reset on UNIX

Hello, We have Windows 10 machine connected to Sparc T5440 server via serial cable. We access the server from the Windows 10 machine using putty via serial connection. This allows us to access ILOM and Unix. We have recently noticed that whenever we reboot the windows machine (Windows 10),... (11 Replies)
Discussion started by: jasonu
11 Replies

2. Shell Programming and Scripting

Execute shell script on remote machine

I want to execute a shell script(set of commands) on remote machine and that script takes input from text file(local machine). Please refer below: ssh user@hostname 'bash -s'< ./test.sh file.txt But i got the error file.txt doesn't exist. Can anyone help me on this. Content of test.sh: ... (2 Replies)
Discussion started by: manishtri88
2 Replies

3. UNIX for Dummies Questions & Answers

Execute shell script in remote machine

Hi All, We have 2 servers A and B. B is having a sctipt called b.sh in path /home/dev/scripts. Now my requirement is i want to execute b.sh from server A. Kindly help me. (3 Replies)
Discussion started by: Girish19
3 Replies

4. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

5. Solaris

How to auto start a service on rebooting a Solaris 5.10 x86 machine?

Hi all, How to auto start a snmpd deamon on rebooting a Solaris 5.10 x86 machine. snmpd's path: /opt/download/net-snmp/sbin Thank you in advance. (6 Replies)
Discussion started by: ziosnim
6 Replies

6. Shell Programming and Scripting

Run shell script on different machine using perl script

I want to execute my shell script on remote machine using SSH in perl script. Please help me with syntax. (2 Replies)
Discussion started by: james1988
2 Replies

7. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

8. Shell Programming and Scripting

shell script to copy files frm a linux machine to a windows machine using SCP

I need a shell script to copy files frm a linux machine to a windows machine using SCP. The files keeps changing day-to-day. I have to copy the latest file to the windows machine frm the linux machine. for example :In Linux, On July 20, the file name will be 20.txt and it should be copied to... (3 Replies)
Discussion started by: nithin6034
3 Replies

9. Solaris

How to auto start MySQL server on Opensolaris after rebooting the machine?

Hi, In Linux, I will do it by editing the /etc/rc.d/rc.local . However, I can't find a rc.local file in Opensolaris. So, how can I do it in Opensolaris? I am new to opensolaris, so please teach me step by step. Thanks in advance. (4 Replies)
Discussion started by: AlexCheung
4 Replies

10. Shell Programming and Scripting

Executing shell script on local machine

Hi guys, I need to run and test some shell script. At work, i work on ksh. I don't have any such software/client installed at home and i cannot always connect to work from home. At home i have Windows Vista. Is there a free and reliable software where i can run my ksh script? Please let me... (4 Replies)
Discussion started by: jakSun8
4 Replies
Login or Register to Ask a Question