Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


Closed Thread
  Search this Thread
Old 04-07-2008, 02:13 PM   #1
LQ Newbie
Registered: Mar 2008
Posts: 9

Rep: Reputation: 0
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?

#!/bin/sh --
sleep 45s
if [ ` pidof firefox-bin` ]; then
sleep 15s
sudo /sbin/shutdown - h now
exit 0
This may be related to a previous post that I had:
Old 04-07-2008, 02:28 PM   #2
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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:
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:
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.
Old 04-07-2008, 02:50 PM   #3
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913
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.

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems running PHP script in command line Hondro Linux - Software 1 06-21-2007 05:16 AM
Problems running PHP scrip in command line Hondro Programming 0 06-21-2007 03:39 AM
Red Hat Server Problems with Command Line and MySQL jazee Linux - Software 1 07-04-2006 11:19 AM
Nvidia command line problems hypershadow147 SUSE / openSUSE 1 04-02-2005 02:19 PM
mouse problems in Gentoo command line khermans Linux - Newbie 2 06-16-2004 09:18 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration