LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 10-30-2007, 12:16 AM   #1
kkiwi8
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Rep: Reputation: 0
Help in scripting


Need help, since I am a newbie to scripting .. tia.

I have a file named Rooms.out, which may have the following entries in it. This file gets generated every 30 minutes.
Room1
Room2
...

Depeneding on the entries in Rooms.out, I have to generate another file Exams.out in the following format

Tue Oct 30 04:00:04 Exam is being conducted in Room1
Tue Oct 30 04:30:04 Exam is being conducted in Room2
...

In the next 30 mintes, If Rooms.out has the following entries
Room1
Room3

in the Exams.out file, I have to add a new line for Room3 and delete the line which has Room2.

Thanks.
 
Old 10-30-2007, 12:44 AM   #2
ehawk
Senior Member
 
Registered: Jul 2003
Posts: 1,257

Rep: Reputation: 48
This page has links in the left-hand margin that describes how to do many common tasks in linux

http://lowfatlinux.com/linux-compare-files-diff.html

Your task seems like searching for and replacing regular expressions, so maybe this one will help:

http://lowfatlinux.com/linux-sed.html
 
Old 10-30-2007, 09:39 AM   #3
kkiwi8
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the links. It did give me an idea of what I am trying to achieve.
But, I actually need some help scripting itself, meaning, how I put it in a script. If I can get some handhold in starting to write the script that will be great. If this is not the correct forum for that, please redirect me to the appropriate one. Thanks.
 
Old 10-30-2007, 10:16 AM   #4
ehawk
Senior Member
 
Registered: Jul 2003
Posts: 1,257

Rep: Reputation: 48
Here is a basic introduction to shell scripts in linux:

http://www.freeos.com/guides/lsst/

specifically,

http://www.freeos.com/guides/lsst/ch02sec01.html

Last edited by ehawk; 10-30-2007 at 10:17 AM.
 
Old 10-30-2007, 11:53 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
also---an excellent book is "Bash Guide for Beginners"----free at http://tldp.org

Easy way to get started:

Practice with individual commands in the terminal.
Then, open an editor and type:
#!/bin/bash
<some command>

Save the file and use chmod to make it executable, then run it using:
./filename

Keep adding commands to the file and you will be building a script.

Last edited by pixellany; 10-30-2007 at 11:57 AM.
 
Old 10-31-2007, 04:01 PM   #6
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Where are the timestamps in Exams.out coming from? Can they be re-generated at a later time?

Is the text " Exam is being conducted in " a constant?

How far have you gotten? -- Do you have any sample code for us to critique?
 
Old 11-02-2007, 10:41 AM   #7
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
Maybe I'm simplifying this way too much

So rooms.out will contain only the rooms we care about right?

seems to me a simple

for i in `cat rooms.out` ; do echo `date` exam is being conducted in $i ; done > Exams.out

would work. if you want the date formatted do a man date and pick how you want.
 
Old 11-02-2007, 11:26 AM   #8
farkus888
Member
 
Registered: Oct 2006
Distribution: usually use arch
Posts: 103

Rep: Reputation: 15
Quote:
Originally Posted by Blinker_Fluid View Post
Maybe I'm simplifying this way too much

So rooms.out will contain only the rooms we care about right?

seems to me a simple

for i in `cat rooms.out` ; do echo `date` exam is being conducted in $i ; done > Exams.out

would work. if you want the date formatted do a man date and pick how you want.
I think a script that runs that code put in cron to run every half hour would be the perfect solution. the orginization of cron varies from distro to distro so we'll need to know what distro this is to help you with the cron entry
 
Old 11-03-2007, 12:05 AM   #9
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Not if there is a need to maintain the orig. timestamp for rooms that are in use for more than 1/2 hr. -- as implied by the example in the OP.

To my "Where are the timestamps in Exams.out coming from? Can they be re-generated at a later time?", maybe I should add: "Once determined, must they stay the same?"
 
Old 11-06-2007, 07:37 PM   #10
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
Quote:
Originally Posted by archtoad6 View Post
Not if there is a need to maintain the orig. timestamp for rooms that are in use for more than 1/2 hr. -- as implied by the example in the OP.

To my "Where are the timestamps in Exams.out coming from? Can they be re-generated at a later time?", maybe I should add: "Once determined, must they stay the same?"
ah missed that ready for my next hack job?

for i in `cat rooms.out` ; do echo `date` exam is being conducted in $i ; done >> Exams_tmp.out
for i in `cat rooms.out` ; do grep $1 Exams_tmp.out | head -1 ; done > Exams.out
cp Exams.out Exams_tmp.out

Basic logic just in case you need some explaination...
We are appending the current list onto the Exams_tmp.out file (which would contain whatever was in the last round), then take the first instance we find and stick it in the Exams.out (earliest time stamp), then copy the Exams.out to Exams_tmp.out so we are ready next time the script runs.
 
  


Reply

Tags
scripting



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
I need help with scripting -- Please help xmdms Linux - Newbie 2 08-09-2006 11:16 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
Scripting CICA Linux - General 7 10-03-2005 10:36 AM
Need help scripting Tamara Programming 7 06-06-2005 02:06 AM
HELP!! with scripting eggoz Linux - General 1 04-25-2003 07:52 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 06:03 PM.

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