linux - Empty /var/log after running cron bash script
2014-07
I wrote a little bash script and all of a sudden my /var/log folder is completely empty except for the log I created for the bash script.
This is the script I'm running every hour with cron:
#!/bin/bash
STL_DIR=/path/to/some/folder/i/hid
LOGFILE=/var/log/stl_upload.log
now=`date`
echo "----------Start of Transmission----------" 2>&1 | tee -a $LOGFILE
echo "Starting transfer at $now" 2>&1 | tee -a $LOGFILE
rsync -av -e ssh $STL_DIR [email protected]:/users/path/folder 2>&1 | tee -a $LOGFILE
echo "----------End of transmission----------" 2>&1 | tee -a $LOGFILE
printf "\n" 2>&1 | tee -a $LOGFILE
I want to be clear that I'm not 100% certain this is related to the empty logs folder. So if anyone could give me a pointer as to what could be going on about the reason why my log folder is empty, that'd be great.
It is still unknown what happened, but a server reboot regenerated the log files again (had to touch a couple manually). Still very strange issue, but as we are moving to a new environment (managed by a 3rd party) this week, this question is considered answered.
Just curious, your logrotate or syslog.conf config might be archiving logs to a different directory? And it was all just coincidence? Can't think of any other reason. (I realize this question is answered, I'm just curious too)
I am using CentOS 5.4. I created a bash script that does some checking before running any commands. If the check fails, it will simply exit 0
. The problem I am having is that on our server, the script will exit the su
or ssh
session when the exit 0
is called.
#!/bin/bash
# check if directory has contents and exit if none
if [ -z "`ls /ebs_raid/import/*.txt 2>/dev/null`" ]; then
echo "ok"
exit 0
fi
here is the output:
[root@ip-10-251-86-31 ebs_raid]# . test.sh
ok
[russ@ip-10-251-86-31 ebs_raid]$
as you can see, I was removed from my sudo session, if I wasn't in the sudo session, it would have logged me out of my ssh session. I am not sure what I am doing wrong here or where to start.
When you use .
to run a shell script it executes in the current shell rather than starting a new shell. Type bash test.sh
to get the behaviour you want.