Need help writing shell script!


 
Thread Tools Search this Thread
# 1  
Need help writing shell script!

Hi, I'm very new to this, so bear with me please.

I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then printing the date again in 1.out.

So basically something along the lines of:

example.sh
date
./program.exe argv[0] argv[1] >> 2.out #argv[0]_argv[1].out rather than 2.out
date

and I would run example.sh like so:

sh example.sh a.fa b.fa >> 1.out

and 1.out would read:

date1
date2

and 2.out would be the output of the program.

I would also like to name 1.out --> a_b_time.out and 2.out -->a_b.out

Any degree of help would be greatly appreciated.
# 2  
Not sure to understand correctly.
Could you please give more clue about what you are trying to achieve ?

Code:
my_log_$(date +%Y%m%d_%H%M%S).out

# 3  
Yes, sorry.

So basically I want to run a program and track the start time, the time when the program starts running, to the end time, when the program is finished. What I want the shell script to do is to print the start time to a file, use the arguments entered in the command line as arguments for the program I'm running, and then print the time after the program is done running in the same file that the start time was printed to. I want the file containing the start and end times to be called firstargument_secondargument_time.out and the program output to be called firstargument_secondargument.out.

If there is another method of figuring out how long the program runs for of if you have any more questions, please let me know.
# 4  
Sorry but i still don't understand what is the point.
Logging the start and end time into a log should be sufficient.

Code:
$ cat example.sh
MYLOG=my_log_$(date +%Y%m%d_%H%M%S).out
exec >>$MYLOG 2>&1
date
echo start sleeping
sleep 10
date
exec >&-
$ sh example.sh
$ ls -rt | tail -1
my_log_20121102_210927.out
$ cat my_log_20121102_210927.out
vendredi 2 novembre 2012, 21:09:27 (UTC+0100)
start sleeping
vendredi 2 novembre 2012, 21:09:37 (UTC+0100)
$

Code:
$ cat example2.sh
date >mylog2.out
echo "Run some random prog" >>mylog2.out
sleep 10 >>mylog2.out
date >>mylog2.out
$ sh example2.sh
$ cat mylog2.out
vendredi 2 novembre 2012, 21:15:52 (UTC+0100)
Run some random prog
vendredi 2 novembre 2012, 21:16:02 (UTC+0100)
$

?
# 5  
This is a duplicate of another thread Need help writing shell script! in the Shell Programming and Scripting forum and was answered there a few hours ago.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help in writing shell script

Dear Team, Below is the list of steps i need to perform manually as of now and completely new to shell scripting, could you help in writing a shell script to perform the below procedure? 1. Log in to primary DNS server 2. Check /etc/named.conf if zone is already created (grep –i... (2 Replies)
Discussion started by: VKIRUPHAKARAN
2 Replies

2. Shell Programming and Scripting

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (2 Replies)
Discussion started by: ShiGua
2 Replies

3. Shell Programming and Scripting

Writing a shell script

Hi I have two files a.log and b.log . i need to append a.log and b.log so that at the end of first line in a.log i need the append the data of first line from b.log and end of the second line in a.log i need to append the data of second line from b.log and so on up to the end of the file can... (3 Replies)
Discussion started by: lalu
3 Replies

4. UNIX and Linux Applications

Need help in writing shell script

I have written a shell script and when i ran the script,for some point of time it is asking to press enter key manually using keyboard.So i need it the enter key in shell itself. ex : in my shell script,i used the command ssh-keygen -t rsa so it asks the enter 3 times. can you please let me know... (3 Replies)
Discussion started by: lkeswar
3 Replies

5. Shell Programming and Scripting

Need help in writing the shell script

Can anyone please help me in writing a shell script that would check if a particular user(xyz) has logged in, and if yes, the audit daemon needs to be started. When the user logs off the dameon needs to shutdown , and the report needs to be e-mailed to a set of users. (12 Replies)
Discussion started by: ggayathri
12 Replies

6. Shell Programming and Scripting

Writing shell script

Hi, I am a new for shell script. i need to write script using the following commands cd /usres/test # create directory mkdir temp+DATE( i need to append date ) #moving files from one directory to this directory(we need to check total files in source and taget) cd /users/sample ... (2 Replies)
Discussion started by: bmkreddy
2 Replies

7. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

8. Shell Programming and Scripting

Need help for writing shell script

Hello ALL, I am fresher in Unix . i need help to write small shell script . Please help me unix guru. I am developing the internal site in my office . the data files are generated in one directory everyday . I have to write shell script to sort those files and put it is internal site . ... (3 Replies)
Discussion started by: deepa20
3 Replies

9. UNIX for Dummies Questions & Answers

Writing a shell Script

How to write a shell script file to read 5 numbers using a while loop. Finding the average, maximum and minumum for the numbers. Any help would be great. (1 Reply)
Discussion started by: Chin
1 Replies

10. Shell Programming and Scripting

Need help with writing shell script

I have the following output. I want to write a script to check for 1. waits > 0 on all rowsand Ratio > .0. if true then send email. ========================= ROLLBACK SEGMENT CONTENTION ========================= If any ratio is > .01 then more rollback segments are needed NAME ... (1 Reply)
Discussion started by: jigarlakhani
1 Replies

Featured Tech Videos