Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting ? passing a file to another script ? 1

Status
Not open for further replies.
Apr 2, 2002
25
US
Ok.... I have a script that is going to take two console logs named the same thing (console.xxxx.gz) in two different directories and tar them up.

The question is... How do I pass the files... /usr/console/logs/PR/console.0506.gz and /usr/console/logs/DT/console.0506.gz to the script below ? I'm confused because as you can see the above console logs will change the name every day.

#!/bin/sh
date=`date "+%m%d%Y"`
tar -cf console_log.$date <files_here>

 
OK.... I'm confused with that responce.

How is that going to pass the 2 different console logs from 2 different directories to the script ??
 
that's what &quot;$1&quot; and &quot;$2&quot; are for.

I presume the rest of script was left as an exercise to the reader.
 
Megawicked:

Get the files you want into an ASCII file, one per line. For example if your file: xx contains:

/usr/console/logs/PR/console.0506.gz
/usr/console/logs/DT/console.0506.gz

you can do this:

tar -cf console_log.$date `cat xx`

you probably use the find command to create xx


find . -name &quot;*0506*&quot; -print

After you've developed your find command you can do this:

tar -cf console_log.$date `find . -name &quot;*0506*&quot; -print`

Regards,

Ed


 
I hate to hard code anything, generally I have a sysadmin.var or variables file and a sysadmin.fnc or functions file that I put at the begining of every script then it will source all the standard variables and paths as well as some functions that I don't want to script all the time.

#!/bin/ksh
today=`date &quot;+%m%d%Y&quot;`
logdir=/usr/console/logs
logdir1=${logdir}/PR
logdir2=${logdir}/DT

workdir=/usr/local/logs/sysinfo/`hostname`

log1=${logdir1}/console.${today}.gz
log2=${logdir2}/console.${today}.gz

tar cf ${workdir}/console_log.${today} ${log1} ${log2}

(I don't know where you want to put the new console_log file)

You can now run this script in cron... Generally I will send the output of the script to a directory called /usr/local/logs/sysinfo/`hostname` in which the parent /usr/local/logs is automounted to all servers. Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top