LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command Line Problems (https://www.linuxquestions.org/questions/linux-newbie-8/command-line-problems-633712/)

guardiantorj 04-07-2008 01:13 PM

Command Line Problems
 
I am running a script with an IF statement but I need it to wait 45seconds before it starts. But with the sleep there it works but skips my if statement for some reason and shuts down even though firefox is open. Any thoughts?

Code:

#!/bin/sh --
sleep 45s
if [ ` pidof firefox-bin` ]; then
sleep 15s
fi
sudo /sbin/shutdown - h now
exit 0

This may be related to a previous post that I had:

http://www.linuxquestions.org/questi...rsions-631968/

matthewg42 04-07-2008 01:28 PM

I don't understand the purpose of this script. I think you want something which does this, right?
  • wait for 45 seconds
  • if firefox is running, sleep another 15 seconds
  • no matter if firefox was running or not, shutdown the computer
Weird script!
I think what you want to do is change the id statement like this:
Code:

if pidof firefox-bin; then
And if you don't want to see the PID printed on the terminal, you can re-direct stdout like this (and then we will just use the exit status of pidof:
Code:

if pidof firefox-bin > /dev/null; then
Note that sudo will probably prompt you for a password. I assume you've set up the sudoers file to make it possible to run shutdown without being prompted for the password.

Tinkster 04-07-2008 01:50 PM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
http://www.linuxquestions.org/questi...8/#post3107494


All times are GMT -5. The time now is 08:42 PM.