Operating System - HP-UX
1833144 Members
3305 Online
110051 Solutions
New Discussion

Re: writing a small script

 
SOLVED
Go to solution
Berson Mark
Occasional Contributor

writing a small script

Hi

i m sorry , but i dont have a lot of knowlege with shelling ,

i want to write a script that will do this :

1. check in i have in / a core file
2. run the command file and what on the core file and report this info to a file .

i will run it on crontab so i dont need to run it with a loop .

thanks
5 REPLIES 5
Pete Randall
Outstanding Contributor
Solution

Re: writing a small script

I haven't been able to try this one but,

00 02 * * * /usr/bin/find / -type f -name "core" -exec file > /home/root/core_report {} \;

should probably be close to what you're looking for.


Pete

Pete
Jean-Luc Oudart
Honored Contributor

Re: writing a small script

1) write a script :
e.g. name=/usr/local/bin/chk
#!/bin/sh

what $1 >/tmp/$1.what
file $1 >/tmp/$1.file

2) run the command
find / -name core -exec /usr/local/bin/chk {} \;

Regards,
Jean-Luc
fiat lux
Pete Randall
Outstanding Contributor

Re: writing a small script

Sorry, I should have mentioned that that was intended to be a crontab entry running at 2:00 AM everyday.


Pete

Pete
Mark Grant
Honored Contributor

Re: writing a small script

find . -name core -exec file {} \; -exec what {} \; >> outputfile
Never preceed any demonstration with anything more predictive than "watch this"
Jeroen Peereboom
Honored Contributor

Re: writing a small script

If you only want to search in /, and not in other fielsystems, add a '-xdev' to your find statement.

find / -xdev -name core -type -exec file {} >> yourlogfile \;

This will only search the root filesystem, find regular (normal) files, and executes the 'file' command, and APPEND the output to yourlogfile.

Since you may want to execute several commands on 1 core-file, I think you should follow Jean-Luc's solution by writing a separate script to do this.


I would prefer something like:
#!/bin/sh

(
echo $1
what $1
file $1
) >> /root/yourlogfile

Or even put the date in the logfilename.
(something like: yourlogfile=/root/logfile`date "+...."`
and change the last line to:
) >> $yourlogfile

JP.