help me in this script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help me in this script
# 1  
Old 11-26-2011
Power help me in this script

I have a directory
Code:
/mo/omar/teefa/filesDBM

it contains files that all start with BMW and ends with .txt for example
Code:
IBM0001.txt
IBM0002.txt
...............

my script test.sh
Code:
file=$1       # source file 
file=$2       # temp file will be removed 
file2=$3     # output file 

awk ' /testname/ { print $1 } /TypeModel/ { print ":" $3 } ' / $file >> $file1
paste -d ";" $file $file1 >> $file2
rm $file1

i wanna make the output file to be named automatically by date for example
Code:
22112011.txt             or 12011.txt
23112011.txt             or 22011.txt

and i wanna make it runs automatically every day at 10 am
[ each day at 10 am ./test.sh ]
and to put its input automatically by making a script to search in the given directory for the files starts with BMW and ends with .txt [ take care make it to rename files . processing and .done ] to prevent that file it taken twice Smilie

finally: a scripts search certain source files and runs every day at 10 am and all ouput in a file named by date Smilie thanks alot waiting your brilliant replies
# 2  
Old 11-28-2011
cron to execute everyday

Try looking in to the cron command to schedule your script to run.
# 3  
Old 11-28-2011
Hi you can use the date command inside backticks (`) in order to provide a date as filename for the output file, i.e.:
Code:
/path/to/test.sh 1st_param 2nd_param `date '+%Y%M%d'`.txt

resulting in the third parameter being expanded by the shell as: 20111128.txt (that is YYYYMMDD.txt).

See man pages for date command for formatting date output.
see ya
fra
This User Gave Thanks to frappa For This Post:
# 4  
Old 11-28-2011
Quote:
Originally Posted by frappa
Hi you can use the date command inside backticks (`) in order to provide a date as filename for the output file, i.e.:
Code:
/path/to/test.sh 1st_param 2nd_param `date '+%Y%M%d'`.txt

resulting in the third parameter being expanded by the shell as: 20111128.txt (that is YYYYMMDD.txt).

See man pages for date command for formatting date output.
see ya
fra
thanks alot
what if i wanna get all ,txt files in this directort without overwritting
# 5  
Old 11-28-2011
hi,

i don;t know if I fully understood your last question, but you could think about using hour, date and time in the output files in order to differentiate the filenames among different executions of the script in the same day.

fra
# 6  
Old 11-28-2011
ok vor this part for output
i want my input files to be taken from a certain path ( all starts with IBM and end .txt )
and take them by order without overwriting (taken twice ) . is it ok now ?
# 7  
Old 11-28-2011
ok,
so you could just use a for cicle to call your script, like:
Code:
for sourcefile in `ls /mo/omar/teefa/filesDBM/IBM*.txt` ; do /path/to/test.sh $sourcefile 2nd_param 3rd_param ; done

The shell will expand the
Code:
`ls /mo/omar/teefa/filesDBM/IBM*.txt`

by returning all the filenames contained in the path.
Be aware: the ls commend will return both files and subdirectories as well as links contained in /mo/omar/teefa/filesDBM, so if you want only filenames returned, use the find command instead (see man find with particular reference to the -t, -name and -print options).

Obviously, you can use the `date` trick to obtain output filenames based on dates.
You can use the previous one-liner right in the crontab.

see ya
fra

P.S.
please be also aware of the -maxdepth option in find (it limits the scope to the directory passed as argument, thereby avoiding subdirectory recursion).
Finally, ls without other time-related switches guarantees that filenames are returned in alphabetical order (by the way, digits are actually considered strings); I'm not sure that the -name switch of find does the same.

Last edited by frappa; 11-28-2011 at 04:52 PM.. Reason: added some further additional clarification
This User Gave Thanks to frappa For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question