Bash script wont exit?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script wont exit?
# 1  
Old 03-20-2011
Bash script wont exit?

Solved Stupidly I didn't put brackets around the , thanks for all the help guys
if ps ax | grep Cluster__check.bash | grep -v grep > /dev/null -- fails
(if ps ax | grep Cluster__check.bash | grep -v grep > /dev/null) --works

Last edited by danmc; 03-20-2011 at 07:30 PM..
# 2  
Old 03-20-2011
It might look like it works, but it doesn't

Bash if doesn't work as such. The if gets help from the test program. To make it look more in line with other programing language syntax, the test command has an alias, `[' (open square bracket ), followed by a close bracket `]'. That's why you don't see the test word written all that often.

Your statement should have been
Code:
if [ -n `ps ax | grep Cluster__check.bash | grep -v grep > /dev/null` ]; then
    # do something
fi

Or something similar to it.
# 3  
Old 03-20-2011
No I think he is wanting to test the return code of the final grep command
I'd be more inclined to do:
Code:
ps ax | grep -q '[C]luster__check.bash'
if [ $? -eq 0 ]; then
    # it's still running
fi

# 4  
Old 03-20-2011
Quote:
Originally Posted by Chubler_XL
No I think he is wanting to test the return code of the final grep command
I'd be more inclined to do:
Code:
ps ax | grep -q '[C]luster__check.bash'
if [ $? -eq 0 ]; then
    # it's still running
fi


Thanks thats how I finally got it to work I should have posted the working script up rather than deleting it, I'll put it back up tomorrow.

Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Terminal running bash/rsync script does not close with exit (MacOS High SIerra)

Hello, I am running a bash script to do an rsync back on a computer running MacOS High Sierra. This is the script I am using, #!/bin/bash # main backup location, trailing slash included backup_loc="/Volumes/Archive_Volume/00_macos_backup/" # generic backup function function backup {... (12 Replies)
Discussion started by: LMHmedchem
12 Replies

2. Shell Programming and Scripting

[BASH] Script to manage background scripts (running, finished, exit code)

Heyas, Since this question (similar) occur every now and then, and given the fact i was thinking about it just recently (1-2 weeks) anyway, i started to write something :p The last point for motivation was... (17 Replies)
Discussion started by: sea
17 Replies

3. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

4. Ubuntu

Exit user in bash script

I'm writing a bunch of scripts to automatically configure Ubuntu and I want to run the code below to remove the white dots from the login screen: sudo xhost +SI:localuser:lightdm sudo su lightdm -s /bin/bash gsettings set com.canonical.unity-greeter draw-grid false The problem is that... (3 Replies)
Discussion started by: maerlyngb
3 Replies

5. Shell Programming and Scripting

Bash Shell Script Exit Codes

Here is my daily stupid question: How can I tell a script to only execute if the other scripts exits successfully? So "script A" executes and it executes successfully (0),then "script B" will run or else "script A "executes and it exits unsucessfully (1) then "script B" will read return... (6 Replies)
Discussion started by: metallica1973
6 Replies

6. Shell Programming and Scripting

Shell script wont execute

Im using a script that writes a random line to a text file then executes another shell script. My problem is that the lottery shell script will not execute. Im not receiving an errors when running the shell script, and it copies a random line of text to mtest.txt fine. #!/bin/bash nscripts=2... (3 Replies)
Discussion started by: kylecn
3 Replies

7. Shell Programming and Scripting

Quitting a bash script... any alternatives to exit?

Folks, Below is a basic synopsis of the problem. I have a script that I need to check for some env vars and fail (exit the script) if they are not there. At the same time I need to set some default env vars. To do this I must run the script from the parent shell or source the script. Doing... (3 Replies)
Discussion started by: bashN00b
3 Replies

8. UNIX for Dummies Questions & Answers

Tcl script wont run in bash shell

Hello I'm having a problem running a TCL script in my new OpenSolaris OS. When I go to the directory containing my script called 'Install' (using the gnome terminal), it doesn't seem to be able to find it even though it lists it i.e. if I type "Inst" and hit tab to complete the word, it... (11 Replies)
Discussion started by: sbsbg
11 Replies

9. Shell Programming and Scripting

script wont run

$ ls -l total 44 drwx------ 2 ivanachu users 512 Dec 6 19:15 VILEARN -rw------- 1 ivanachu users 74 Dec 5 18:42 cond -rwx------ 1 ivanachu users 97 Dec 5 21:30 cond2 -rwxrwxrwx 1 ivanachu users 4979 Feb 10 22:42 createHAqmgr.ksh -rw------- 1 ivanachu users 28 Dec 4... (10 Replies)
Discussion started by: ivanachukapawn
10 Replies

10. Shell Programming and Scripting

why wont this script run?

i have this script i wrote, it chokes when running the add install client commandit keeps telling me the add_install_client command is incorrect. When I put the print statement in front of the command so it will echo it, the command looks right on the screen. Yes im am an ametuer, im trying to... (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies
Login or Register to Ask a Question