You are not logged in.

#1 2009-12-24 08:25:42

heyya
Member
Registered: 2009-05-23
Posts: 30

[SOLVED]bash script

I had created a bash script which ensures that each of the applications has one instance. The problem is no applications are executed during startup. Here is my script:

if [ -z "ps aux | grep wmCalClock | head -n -1" ]
        then
                 wmCalClock -b 100 -arial -tc cyan -bc black -e xterm &
fi

if [ -z "ps aux | grep wmfire | head -n -1" ]
        then
                wmfire -L1 -B1 -s0 -C2 -P fireload_temp &
fi

if [ -z "ps aux | grep wmcpuload | head -n -1" ]
        then
                wmcpuload -lc red -a 95 &
fi

if [ -z "ps aux | grep wmmemload | head -n -1" ]
        then
                wmmemload -lc red -am 95 &
fi

Last edited by heyya (2009-12-25 04:19:33)

Offline

#2 2009-12-24 08:37:54

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: [SOLVED]bash script

Well, obviously not, as the string "ps aux | grep wmCalClock | head -n -1" is
never empty wink What you probably wanted to write is

"$(ps aux | grep wmCalClock | head -n -1)"

This will put the output of the script into the string, rather than taking the
command string itselft.

Offline

#3 2009-12-24 08:40:29

heyya
Member
Registered: 2009-05-23
Posts: 30

Re: [SOLVED]bash script

thanks

Offline

#4 2009-12-24 08:57:57

heyya
Member
Registered: 2009-05-23
Posts: 30

Re: [SOLVED]bash script

Oops! "$(ps aux | grep wmCalClock | head -n -1)" should be "$(ps aux | grep wmCalClock | head -n 1)" and also for the rest.

Last edited by heyya (2009-12-24 08:58:08)

Offline

#5 2009-12-24 09:11:10

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: [SOLVED]bash script

Just a hint for you:

I'm not sure if this will work the way you expect it. At least for me, doing a
grep on a ps output usually yields the grep itself, which is not a problem if
I'm looking at it. For use in a script like this, however, it might become a
problem.

Offline

#6 2009-12-24 09:14:46

Kitty
Member
From: The Burning Desert
Registered: 2008-01-11
Posts: 88

Re: [SOLVED]bash script

Use pgrep.


/etc/rc.d/ is where daemons reside. Beware.

Offline

#7 2009-12-24 12:49:10

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED]bash script

Kitty wrote:

Use pgrep.

This, and note that pgrep also returns true/false beside stdout. So you can do if ! pgrep wmCalClock; then wmCalClock; fi

Offline

#8 2009-12-25 04:09:59

heyya
Member
Registered: 2009-05-23
Posts: 30

Re: [SOLVED]bash script

thanks guys

Offline

Board footer

Powered by FluxBB