- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script to check file existence and notify
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
Discussions
Discussions
Forums
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
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
тАО11-02-2004 06:52 PM
тАО11-02-2004 06:52 PM
script to check file existence and notify
Need help on my script. I wanted to have a script that will check the file in the directory, if not match then send e-mail to user. I have configured the mail the only thing is to make my script work.
#!/bin/sh
date=`date '+20%y-%d-%m'`
#Check if file is match in the directory
ls -ltr xyz.$date:*
#if not the send to mail
mailx -s "file not match" user@abc.foo.com << EOF
Please check your file
br,
Munawawr(script beginner)
- Tags:
- ls
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2004 07:04 PM
тАО11-02-2004 07:04 PM
Re: script to check file existence and notify
#!/bin/sh
today=$(date +%Y-%m-%d)
for file in xyz.${today}:* ; do
if [ ! -f $file ] ; then
mailx -s "${file}: file not match" user@foo.com << EOF
Please check for file $file.
EOF
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2004 07:41 PM
тАО11-02-2004 07:41 PM
Re: script to check file existence and notify
read the manpage for 'test'.
There you can find all possibilities to check a file:
-r file True if file exists and is readable.
-w file True if file exists and is writable.
-x file True if file exists and is executable.
-f file True if file exists and is a regular file.
.
.
.
and so forth
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2004 07:57 PM
тАО11-02-2004 07:57 PM
Re: script to check file existence and notify
Another way as, To do your work then,
#!/bin/sh
date=`date '+20%y-%d-%m'`
#Check if file is match in the directory
ls -ltr "xyz.${date}:*" 1>/dev/null 2>&1
#if not the send to mail
if [[ $? -ne 0 ]]
then
mailx -s "file not match" user@abc.foo.com << EOF
Please check your file
EOF
fi
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2004 08:09 PM
тАО11-02-2004 08:09 PM
Re: script to check file existence and notify
Be careful with the use of the "new" test "operator" in guise of double square brackets [[ -f ... ]], especially in your intended context.
To my knowledge the "new" test construct does prevent word splitting and filename expansion.
So if you're inclined to use a shell globbing expression in a file test condition that would not work as expected
e.g.
if [[ -d /app/oracle/product/[89].[12].[07] ]]; then
# do soemthing
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2004 08:40 PM
тАО11-02-2004 08:40 PM
Re: script to check file existence and notify
I use this way and it work I got the mail:-
#!/bin/sh
#today=$(date+20%y-%d-%m)
date=`date '+20%y-%d-%m'`
for file in xyz.$date:*;do
if [ ! -f $file ];then
mailx -s "$(file): file not match" user@foo.com << EOF
Please check for file $file
EOF
fi
done
However when it found that the file not match then I got this additional message after run the script:-
usage: file [-c] [-f ffile] [-m mfile] [-h] file...
where I should touch up this?
br,
Munawawr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2004 09:09 PM
тАО11-02-2004 09:09 PM
Re: script to check file existence and notify
You should use the mailx command like this:
mailx -s "$file: file not match" user@foo.com << EOF
Please check for file $file
EOF
Currently you're using command substitution. So if you type file from your prompt you get the same message.
Regards, MB.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2004 10:31 PM
тАО11-02-2004 10:31 PM
Re: script to check file existence and notify
#!/bin/sh
#today=$(date+20%y-%d-%m)
date=`date '+20%y-%d-%m'`
for file in xyz.${date}:*;do
if [ ! -f $file ];then
mailx -s "${file}: file not match" user@foo.com << EOF
Please check for file $file
EOF
fi
done
It will work there.
HTH.