LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Closed Thread
  Search this Thread
Old 04-07-2008, 01:13 PM   #1
guardiantorj
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?

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/
 
Old 04-07-2008, 01:28 PM   #2
matthewg42
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:
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.
 
Old 04-07-2008, 01:50 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
  


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 04:16 AM
Problems running PHP scrip in command line Hondro Programming 0 06-21-2007 02:39 AM
Red Hat Server Problems with Command Line and MySQL jazee Linux - Software 1 07-04-2006 10:19 AM
Nvidia command line problems hypershadow147 SUSE / openSUSE 1 04-02-2005 01:19 PM
mouse problems in Gentoo command line khermans Linux - Newbie 2 06-16-2004 08:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:22 AM.

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