Help with dynamic script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with dynamic script
# 1  
Old 01-18-2011
Help with dynamic script

Hey there, first post, somewhat-long-time lurker-
This is on a Red Hat box
Im working on a new site, and I have an idea for a dynamic CGI script to change who is "on call"
Pretty much, it would pull next name from a text file each week to display it on the site, and just keeps cycling through the names forever.
I have the "shell" of the script, but I don't have the meat-n-potatoes.
What I got so far
Code:
#!/bin/bash
echo "Content-type: text/html"
echo
echo "<html>"
echo  "<head><title>Currently on call</title></head>
echo "<body>"
echo "<pre>"
SCRIPT HERE
echo "</pre></br>"
echo "</body>"
echo "</html>"

I want the SCRIPT part to pull line the next name from namelist.txt based on monday being the start of the week
there are 6 names
any help, would be awesome!

Last edited by Franklin52; 01-19-2011 at 03:33 AM.. Reason: Please use code tags
# 2  
Old 01-18-2011
Your namelist.txt will be format as below. (the person, who was on duty, is marked by @)
Code:
$ cat namelist.txt
Peter
Thomas
Jenny
Simon
Chris
@Amy

With below command, you can get the next name.

Code:
#with above sample, name=Peter
name=$(awk '/@/ {c=NR} {a[NR]=$0}END{print (c==NR)?a[1]:a[c+1]}' namelist.txt )
echo "$name"

With below commands, you can get the file updated, (sed need support -i option)
Code:
sed -i 's/@//' namelist.txt
sed -i "s/$name/@$name/" namelist.txt

Put your script in cronjob, and run on Monday morning.

Last edited by rdcwayx; 01-18-2011 at 11:09 PM..
# 3  
Old 01-18-2011
You are the best! I'll try it first thing in the morning!
# 4  
Old 01-19-2011
No need for a cronjob to update the file, you can use the ISO weeknumber (as returned by %V from date) as the counter:

Code:
let NUM=$(date +%V)%6+1
sed -n "${NUM}p" namelist.txt

Above uses mod 6 to convert week of the year into number from 1 to 6.

It's also easy to get next/last week's name by simply adding/subtracting from the week number:

Code:
let NUM=($(date +%V)+1)%6+1
sed -n "${NUM}p" namelist.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dynamic script and cron

Hello friends, I have a script.sh running, i need to move his generated file to another path and restart it every 24h. is there a way to restart it from a script in a dynamic way without create a duplicate process? script.sh & mv file to /path script.sh & many thanks for your help (7 Replies)
Discussion started by: kraterions
7 Replies

2. HP-UX

Script dynamic find

Hi everyone, im try to write a small script to do something like this new_find.sh#!/usr/bin/ksh PAR=$1 PATH1=$2 find $PATH1 -name $PAR i need to pass the mask of the find by parameter but this dont work sh new_find *.sql /home/somthing any tip ? thanks! (3 Replies)
Discussion started by: lucasmanson
3 Replies

3. Shell Programming and Scripting

Help Create dynamic ksh script from a script

I am currently running 2 scripts to gather data for a 3rd script and would like to combine the 2 scripts into one. Having issues with the final output format. Note cannot post URL so replaced the http stuff with (name) in the examples All scripts contain #!/bin/ksh OS = Red Hat Enterprise... (0 Replies)
Discussion started by: pcpinkerton
0 Replies

4. Shell Programming and Scripting

dynamic input to a script

Hi All, I am stuck in a situation where there is a script, say test1.tcsh which is being called from another script ,say test2.tcsh test1.tcsh:- #!/usr/local/bin/tcsh echo -n "Do you wanna test ??" set answ = $< echo $answ if ($answ =~ "y") then echo -n "enter your name <" ... (1 Reply)
Discussion started by: kavyak
1 Replies

5. Shell Programming and Scripting

Shell script dynamic command

I need to run a shell script with dynamic command in it like # Begin script... mysql xx "select * from tab" | sed 's/\t/|/g' > GENERATED_20100304.txt the dynamic part is 20100304 which should be today's date, and it needs to run every day and create a new file with... (2 Replies)
Discussion started by: nuthalapati
2 Replies

6. UNIX for Advanced & Expert Users

Sql dynamic table / dynamic inserts

I have a file that reads File (X.txt) Contents of record 1: rdrDESTINATION_ADDRESS (String) "91 971502573813" rdrDESTINATION_IMSI (String) "000000000000000" rdrORIGINATING_ADDRESS (String) "d0 movies" rdrORIGINATING_IMSI (String) "000000000000000" rdrTRAFFIC_EVENT_TIME... (0 Replies)
Discussion started by: magedfawzy
0 Replies

7. Shell Programming and Scripting

dynamic editing using shell script

Hi, I would like to edit an input data-file by changing a variable in it in steps: For ex: If my input file is 'big.in', then it has the following data: 2.54 0.01 0.5 0.0 My source code then reads this above line, executes and gives out some output. Then , I want to increment... (1 Reply)
Discussion started by: habzone2007
1 Replies

8. Shell Programming and Scripting

creating dynamic shell script

Hello I am trying to create a dynamic ksh script and I have an issue. I have a script a.ksh and it has got the following lines (for example) #!/bin/ksh # trace mode +x : without trace -x : with trace set +xv echo hi, i am going to create a dynamic script now cat >> dynamic.ks <<EOF... (2 Replies)
Discussion started by: sundarkumars
2 Replies

9. Shell Programming and Scripting

Dynamic variables within shell script

Hi Gurus, I have a requirement of writting the shell script where it should ask me two values FND_TOP=/d02/app/oracle/xxx/fnd/11.5.0 CDCRM_TOP=/d02/app/oracle/xxx/cdcrm/11.5.0 and then keep these values stored as variables for the execution of rest of the script. Because, I have to... (2 Replies)
Discussion started by: isingh786
2 Replies

10. Shell Programming and Scripting

dynamic global script

Hi, I have to create a global dynamic script which should ask for the env or some other variables and then create the soft links. let's say that I have to create ten soft links and the path for these soft links is different for each env for e.g: WDEV: /d02/app/applmgr/wdev/appl/CDCRM/bin... (2 Replies)
Discussion started by: isingh786
2 Replies
Login or Register to Ask a Question