08-01-2008
Problems in generating the mail from cron -- very urgent help me
Hi,
I wrote a script which generates a mail automatically under certain condition. When i execute the script manually in unix the script is getting executed and the condition works accordingly and the mail is also generated. But when it is pu into cron the mail is not generated and the condition also seems to be going wrong. The return code of the mail command is '1'. Please help me out.
Below is my sample format of my script,
#!/bin/sh
echo "The Job Successfully scheduled at : `date` "
cd **to some path**
ls **some condition** > filetmp.dat
while read line
do
grep $line file.dat > a1.dat
res=`echo $?`
echo "$res"
if [ $res = "1" ]
then
len=`echo $line | wc -c`
echo $len
if [ $len = "30" ]
then
subfile=`echo $line | cut -c1-18`
echo $subfile
cd **to some path**
grep TFS $subfile > a2.dat
tfs=`echo $?`
if [ $tfs = "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
while read address
do
echo "
Hi ,
This is an alert " | Mail -s "Test Mail" $address
echo "$? --> Mail Status for $address"
done < "addr.dat"
fi
elif [ $len = "44" ]
then
subfile=`echo $line | cut -c1-18`
echo $subfile
cd **to some path**
grep TFS $subfile > a2.dat
tfs=`echo $?`
if [ $tfs = "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
while read address
do
echo "
Hi ,
This is an alert " | Mail -s "Test Mail: " $address
echo "$? --> Mail Status for $address"
done < "addr.dat"
fi
else
subfile1=`echo $line | cut -c1-35`
echo $subfile1
cd **to some path**
grep TFS $subfile1 > a2.dat
tfs=`echo $?`
if [ $tfs = "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
while read address
do
echo "
Hi ,
This is an alert" | Mail -s "Test Mail:" $address
echo "$? --> Mail Status for $address"
done < "addr.dat"
fi
fi
fi
done < "filetemp.dat"
mv filetmp.dat file.dat
echo "The Job Successfully ended at : `date` "
Mail is not generated when scheduled into cron and the grep condition is not working when scheduled into cron. Please help me...
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I'm having serious problems running cron. I want to create midnight backups of my files on my unix server and there is something wrong with cron.
Here is what I do:
First I saw that cron is running (while logged on as root) by typing "ps -aedf|grep cron" and I noticed that there is 1 instance... (4 Replies)
Discussion started by: pappous
4 Replies
2. UNIX for Dummies Questions & Answers
Hi there,
this time a have a other problem :)
i will start a script over the cron.
if i start the script manual (per command) it works without any problems, but over the cron it doesent work.
my cron looks like this:
26 15 * * * /path/scriptname.sh 2> /path/error.log
there is no... (3 Replies)
Discussion started by: scotty
3 Replies
3. Shell Programming and Scripting
Hello All,
I m newbie to Job scheduling.
Suppose i have 2 files s1.sh and s2.sh i want to make a schedule such as
run s1.sh at 2AM everyday and run s2.sh 9Pm everyday.
Can anyone tell me how to schdule that using CRON and i want to know what is CRON and CRONTAB.
Thanks in advance (2 Replies)
Discussion started by: ravi.sadani19
2 Replies
4. Solaris
Hello I am new user on solaris...
I need to configure my solaris to be able to send mails...
I know mailx command
mailx -s hello address@address.com
but I get an error...
you have mail in /var/mail/root
# hello... User unknown
/dead.letter... Saved message in /dead.letter
what... (10 Replies)
Discussion started by: amon
10 Replies
5. Shell Programming and Scripting
Hi,
My aim is to generate a report using shell script. There are various formats fields coloumns etc.
I want to print in a single line (row) but in different coloumn as given below:
field1 field2 field3 field4
....... ....... ...... .......
The spacing... (1 Reply)
Discussion started by: jisha
1 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I wrote a script which generates a mail automatically under certain condition. When i execute the script manually in unix the script is getting executed and the condition works accordingly and the mail is also generated. But when it is pu into cron the mail is not generated and the condition... (1 Reply)
Discussion started by: thiru_cs
1 Replies
7. UNIX for Dummies Questions & Answers
Hey all.
Im totally new with makeing websites ect
The thing is, i wanted to make one of those pimp games, so i installed a script called mypimpscript.. it works but the 10mins cron jobs dont...
ive tried to set it up in cpanel, but im doing it wrong :S
right now it looks like this php... (1 Reply)
Discussion started by: princess
1 Replies
8. Red Hat
Whats the difference between mail and mailx?
I'm trying to troubleshoot a problem where I can send mail from server A with this `echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS` command but executing the same command from server B throws me this error (Both servers are RHEL)
... (1 Reply)
Discussion started by: RedSpyder
1 Replies
9. Shell Programming and Scripting
Hello.
I would like to do this :
A_VAR_FLAG = "ABCD" +------------+...................................+---------+
...............................|.................|...................................|.............|... (7 Replies)
Discussion started by: jcdole
7 Replies
10. UNIX for Beginners Questions & Answers
Team,
Hope you all are doing fine
I have one admin server which is being used dedicately to run cron jobs on hourly basis, fetching the details from Database which is in a different server.These cronjob are run on every hourly/5 minutes basis depending as per end user requirement.The script... (12 Replies)
Discussion started by: whizkidash
12 Replies
escape(1) Mail Avenger 0.8.3 escape(1)
NAME
escape - escape shell special characters in a string
SYNOPSIS
escape string
DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result.
EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string:
$ var='; echo gotcha!'
$ eval echo hi $var
hi
gotcha!
$
Using escape, one can avoid executing the contents of $var:
$ eval echo hi `escape "$var"`
hi ; echo gotcha!
$
A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For
example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient:
#!/bin/sh
formail -x to -x cc -x resent-to -x resent-cc
| fgrep "$1" > /dev/null
&& exit 0
echo "<$1>.. address does not accept blind carbon copies"
exit 100
To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt
script:
bodytest reject_bcc `escape "$RECIPIENT"`
SEE ALSO
avenger(1),
The Mail Avenger home page: <http://www.mailavenger.org/>.
BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells.
AUTHOR
David Mazieres
Mail Avenger 0.8.3 2012-04-05 escape(1)