LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-09-2005, 05:09 AM   #1
Suinatsa
Member
 
Registered: Jul 2004
Distribution: Slackware, Suse
Posts: 46

Rep: Reputation: 15
Starting a program from a shell script


Hey guys,

I have been trying to write a shell script which is able to run a little programm.

ping -c 2 192.168.1.51
if [$? !=0] ; then
wol --host=192.168.1.1 90:50:A1:EF0:53
echo "Starting up Host"
fi
Thats what I got so far. What I want to do is that the script pings one of my computers in my network.
Whenever it fails I want the script to start the program "wol" which starts up the remote computer by the wake on lan function.

I am a noob in shell programming so it is a minor error most probably. I guess the line

wol --host=192.168.1.1 90:50:A1:EF0:53

has to be different. It is the whole command which has to be executed.

Thx

Suinatsa
 
Old 04-09-2005, 08:06 AM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Are you getting an error when you try to run the script? Perhaps you could tell us what it is.
 
Old 04-17-2005, 12:16 AM   #3
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi Suinatsa,
Looking your script, I guess it is logically correct. However, you must get a syntax error in the line:
Code:
if [$? !=0]
The character "[" is a symbolic link to /usr/bin/test. If you read "man test", you'll see:
1 - when using the alternative "[" "]" you have to separate both the brackets by space;
2 - numerical comparisons are specified by "-eq" for "equal to", "-neĻ for "not equal to".
So, this line should be:
Code:
if [ $? -ne 0 ]; then
I don't know the "wol" command but, the syntax is the same as you use in interactive mode.

Cheers,

Osvaldo
 
  


Reply


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
a script run through a shell program... okeyla Linux - Newbie 1 09-15-2005 10:06 AM
how to cll shell script from c program mili Programming 3 04-27-2005 11:22 AM
call a c program in a shell script jagman Programming 4 04-05-2005 04:58 PM
Communication between shell script and program ZooL Programming 6 08-14-2004 05:44 AM
run shell script in c program u4u Linux - General 1 02-14-2004 02:48 PM


All times are GMT -5. The time now is 01:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration