I am running a bash script as a cron
job. The thing is that I use ls
in the script and it says that absolute path file doesn't exist. But it exists:
function get_curr_video_size()
{
curr_size=`ls -l ${video_name} | awk '{print $5}'`
echo ${curr_size}
}
curr_size=`get_curr_video_size`
${video_name}
is get by another function at earlier point, so it can't be non-existent during get_curr_video_size
call.
Error is:
ls: cannot access /home/pi/draft_videos/03_04_2017/test_03_04_2017_22:05:19.mp4: No such
file or directory`
But the file exists. When I ls
it in terminal it is there:
ls -l /home/pi/draft_videos/03_04_2017/test_03_04_2017_22:05:19.mp4
-rw-r--r-- 1 pi pi 0 Apr 3 22:05 /home/pi/draft_videos/03_04_2017/test_03_04_2017_22:05:19.mp4
If I run my script in a terminal instead as a cron
job, it is ok. Seems like cron
messes up things somehow, but I can't understand why.
I am using Raspbian Jessie on RPI.
cron
definition – Chris Davies Apr 03 '17 at 20:00cron
job actually runs a pyhon script, which usingsubprocess
is starting the script I described. – CuriousGuy Apr 03 '17 at 20:03stat -c '%s' FILENAME
ordu
orwc -c
. In Python, useos.stat
. Not an answer to what's happening, just a pointer to a much better way to accomplish your goal – derobert Apr 03 '17 at 20:20curr_size=$(stat -c %s "$video_name")
? Notice that when a variable is used it's used in double quotes, and backticks have been replaced by the modern$(...)
construct. – Chris Davies Apr 03 '17 at 20:22ls -l
work? – derobert Apr 03 '17 at 20:24ls -l
and it worked. Hmmm, maybe I am missing something. I'll try to investigate more and will let you know guys, Thanks for the suggestions! – CuriousGuy Apr 03 '17 at 20:30ls
of the directory and it is empty at the time of thels -l ${video_name}
. – CuriousGuy Apr 03 '17 at 20:46