LinuxQuestions.org
Review your favorite Linux distribution.
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


Reply
  Search this Thread
Old 05-23-2004, 11:51 AM   #1
madmatt112
LQ Newbie
 
Registered: May 2004
Posts: 4

Rep: Reputation: 0
Unhappy Scripting question!!!!! help, plz!


Hello people! I made this script to run the command "who" every 30 seconds:

#!/bin/bash
#include<stdio.h>

main()
{
int number;
number=1;
sleep 30;
who;
sleep 30;
who;
sleep 30;
who;
if number=1 then
goto main;
}


But for some odd reason it gives me this:

./test: line 16: syntax error near unexpected token `}'
./test: line 16: `}'

But isn't that supposed a CLOSING bracket?! Please help me out, here people!
 
Old 05-23-2004, 12:05 PM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
umm correct me if I'm wrong, but I've thought that bash scripting is a bit different thing than C-programming...I mean, the main() { } -function seems to me like a normal C-function, but is it the same in bash-scripting? I haven't done that that much...

if you want to do bash-scripting, I'd suggest read at least first

man bash

or visit some website telling about bash's way of working...
 
Old 05-23-2004, 12:11 PM   #3
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 389

Rep: Reputation: 52
I'm afraid you're getting C and bash very mixed up. Here's how I'd do it;
Code:
#!/bin/bash

while :
do
	who
	sleep 30
done
One good resource is the Advanced Bash-scripting Guide (http://www.tldp.org/LDP/abs/html/). Don't let the "Advanced" part worry you.

Lyle
 
Old 05-23-2004, 12:16 PM   #4
wrongman
Member
 
Registered: May 2004
Location: Italy
Distribution: Debian Unstable 64bit
Posts: 99

Rep: Reputation: 15
Code:
#!/bin/bash

LOOP=0

while [ $LOOP -lt 10 ]; do
        who
        sleep 5
done
here it is ;-)
 
Old 05-23-2004, 12:17 PM   #5
wrongman
Member
 
Registered: May 2004
Location: Italy
Distribution: Debian Unstable 64bit
Posts: 99

Rep: Reputation: 15
sorry, didn't see that lyle already answered
 
Old 05-23-2004, 03:16 PM   #6
madmatt112
LQ Newbie
 
Registered: May 2004
Posts: 4

Original Poster
Rep: Reputation: 0
Wow! Thank you all VERY much I tested them out, and they work! Oh, and, Lyle_s thanks for that great link! Again, thank you so much!
 
  


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
Scripting question buster_balz Linux - General 8 05-18-2005 03:30 PM
Scripting Question caps_phisto Linux - General 1 11-05-2004 02:43 PM
Scripting Question... Darklight451 Linux - Newbie 3 09-23-2004 05:03 PM
scripting question gearoid Programming 3 05-26-2004 02:43 PM
Scripting question aikitortoise Linux - Newbie 3 11-14-2002 05:18 PM


All times are GMT -5. The time now is 02:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration