LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-11-2014, 01:32 PM   #1
kyu0317
LQ Newbie
 
Registered: Dec 2014
Posts: 2

Rep: Reputation: Disabled
Crontab works differently as manually execute the bash script. How can I fix it?


Hello guys.
I have two problems
Firstly, I make a script which send a report of current log files in every 10 min. When I manually execute the script, if there are no log file, it sends a mail with "no log file to report". However, when the script execute automatically with Crontab, it sends "Filename: *.log"
Secondly, when there is email address in report.txt, if the address is "something@gmail.com", when I check the mail after I run it, the mail address become "something%40gmail.com" like this. How can I fix two issues?
Thank you.

Here is my code:

<<Crontab>>
Code:
*/10 * * * * /home/team_24/Log_Report.bash
<<Log_Report.bash>>
Code:
#! /bin/bash

cd /home/team_24/logs                          

export DIR=/home/team_24/logs

if ls ${DIR}/*.log &>/dev/null

then

        for file in *.log

        do

                touch report.txt

                echo "Filename: $file" >> report.txt

                echo "" >> report.txt

                cat "$file" >> report.txt

                echo "" >> report.txt

                #remove log original log file

                rm -f $file

        done

        #report the log file and remove from log directory

        mail -s "Approved_Client_Report" something@gmail.com < /home/team_24/logs/report.txt

        rm /home/team_24/logs/report.txt

        exit 0

else

touch report.txt

echo "No logfile to report" >> report.txt

mail -s "Approved_Client_Report" something@gmail.com < /home/team_24/logs/report.txt

rm /home/team_24/logs/report.txt

exit 0

fi

Last edited by kyu0317; 12-11-2014 at 02:21 PM.
 
Old 12-11-2014, 01:37 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
The first problem is because of this
Code:
for file in *.log
Instead of
Code:
for file in ${DIR}/*.log
not sure about the second.
 
1 members found this post helpful.
Old 12-11-2014, 02:20 PM   #3
kyu0317
LQ Newbie
 
Registered: Dec 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
The first problem is because of this
Code:
for file in *.log
Instead of
Code:
for file in ${DIR}/*.log
not sure about the second.
thank you. It works fine now u r the best

Last edited by kyu0317; 12-11-2014 at 02:48 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
crontab does not run all lines of a script, but manually it works perfect. Annielover Linux - General 7 05-23-2011 07:17 AM
Bash Script only works when manually running. rivacom Linux - General 6 10-13-2010 08:18 AM
[SOLVED] rsync works differently under tcsh than bash? Vanyel Linux - Software 2 09-01-2009 09:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration