- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Script with flags
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2006 06:31 AM
12-07-2006 06:31 AM
I have a script that does a daily check of a file. If it finds a certain condition, it will email. However, I only want it to email twice. So it will check for flag1 and if it exists it checks for flag2. If both exist, I want it not to email. Here is what I have...it is part of a case statement:
ABCD)
if [ $pcent -lt 15 ]; then
find $TMPDIR -type f -mtime +30 -exec rm -f {} \; #if flags are older than a month remove
if [ -f $TMPDIR/$name.2 ]; then
HERE IS WHERE I AM STUCK
elif [ -f $TMPDIR/$name.1 ]; then
touch $TMPDIR/$name.2
else
touch $TMPDIR/$name.1
fi
mail -t $maila <
From: $name
Cc: $dbagroup
message body
EOF
fi
;;
DEFG)
same as above
EOF
;;
So my problem is that it works great if no flags exist or only flag1. I don't know what to do when it finds both flags. I had "exit" but then the script stops and it doesn't run through the other cases. I had echo "nothing" to /dev/null but then it still emails. I guess I could put the whole email spiel in each if statement, but just thought I would check with you guys to see if there is something much simpler I could be doing.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2006 06:41 AM
12-07-2006 06:41 AM
SolutionI would just set a condition to send mail or not in the check routines and check that condition later. E.g.:
...
ABCD)
if [ $pcent -lt 15 ]; then
find $TMPDIR -type f -mtime +30 -exec rm -f {} \; #if flags are older than a month remove
sendit=y # preset condition
if [ -f $TMPDIR/$name.2 ]; then
sendit= # change condition
elif [ -f $TMPDIR/$name.1 ]; then
touch $TMPDIR/$name.2
else
touch $TMPDIR/$name.1
fi
# check condition
[ "$sendit" ] &&
mail -t $maila <
From: $name
Cc: $dbagroup
message body
EOF
fi
;;
...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2006 06:49 AM
12-07-2006 06:49 AM
Re: Script with flags
There are several ways here. One way is to rearrange your code similar to:
...
if [ ! -f "$name.1" ]; then
touch $name.1
elif [ ! -f "$name.2" ]; then
touch $name.2
else
mail ...
fi
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2006 06:50 AM
12-07-2006 06:50 AM
Re: Script with flags
Classic syntax:
if [ -f ${TMPDIR}/${name}.1 -o -f ${TMPDIR}/${name}.2 ] # -o => OR
then
# at least one file was found
else
if [ -f ${TMPDIR}/${name}.1 -a -f ${TMPDIR}/${name}.2 ] # -a => AND
then
# both were found
else
if [ -f ${TMPDIR}/${name}.1 ]
then
# only file1 was found
else
# only file2 was found
fi
fi
else
# No files were found
fi
Newer more efficient equivalent syntax for Korn and POSIX shell syntax (Note the double ]]'s and [['s meaning the shell evaluates internally rather than using the external test command.):
if [[ -f ${TMPDIR}/${name}.1 || -f ${TMPDIR}/${name}.2 ]] # || => OR
then
# at least one file was found
else
if [[ -f ${TMPDIR}/${name}.1 && -f ${TMPDIR}/${name}.2 ]] # && => AND
then
# both were found
else
if [[ -f ${TMPDIR}/${name}.1 ]]
then
# only file1 was found
else
# only file2 was found
fi
fi
else
# No files were found
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2006 01:57 AM
12-08-2006 01:57 AM