Operating System - HP-UX
1835658 Members
3508 Online
110082 Solutions
New Discussion

Please Help with small Script

 
Angie_1
Regular Advisor

Please Help with small Script

Can someone please help me with something real basic? I don't have much experience with scripting. I need to determine whether some files exist on the systems or not and have all of the results write out to a file named 29_XXXXXXXX.

I am stumped and this is how far I've gotten.

Thanks - Angie

echo "Item #29 -- Determine if various log files exist."

if [ ! -d /etc/wtmpx]; then
echo wtmpx file doesn't exist > 29_wtmpx
# /etc/utmpx \
# /var/adm/utmpx \
# /var/adm/loginlog \
# /var/adm/sulog \
# /var/adm/messages \
# /var/cron/log \
# /var/log/syslog \
1 REPLY 1
Sundar_7
Honored Contributor

Re: Please Help with small Script

With scrpting, you can do the same thing in umpteen differen ways :-)

Here is the one version

1) Create a file that lists all the log files that you would like to check for

# vi /usr/local/bin/LOGFLLIST
/etc/utmpx
/var/adm/utmpx
/var/adm/loginlog
/var/adm/sulog
/var/adm/messages
/var/cron/log
/var/log/syslog
#

2) Now the script

# vi /usr/local/bin/script
LIST=/usr/local/bin/LOGFLLIST
OUTLOG=/usr/local/bin/29_output

echo "Item #29 -- Determine if various log files exist."

for FILE in $(cat ${LIST})
do
if [[ -f $FILE ]]
then
echo "Log file ${FILE} exists !" >> $OUTLOG
else
echo "ERROR: Log file ${FILE} doesnt exists !" >> $OUTLOG
fi
done

-- Sundar
Learn What to do ,How to do and more importantly When to do ?