Ok, here is the script. The idea is that it checks a directory for jpeg files, gets the file names, writes the names to a text file, moves the jpeg files to another directory (for sanitation later), and inserts the filenames in to a mysql database.
Code:
#!/bin/bash
ls -l | awk '{print $8}' | grep .jpg >> output.txt
if [ ! -s output.txt ]
then
rm output.txt
exit 0
fi
while read -r LINE ;
do mv "$LINE" ../img/"$LINE" ; done < output.txt
mysqlimport -u username --password=password --local -c filename databasename output.txt
rm output.txt
exit 0
The file itself is running in /var/www/temp.
I have added the following lines to my crontab (tried in user and root crontab):
Code:
# m h dom mon dow command
SHELL=/bin/bash
PATH=:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#*/1 * * * * /var/www/temp/img_prep
img_prep is the script filename.
I think it has something to do with either my path (the script needs to know where it is relative to the files it needs to work with/find) or it has to do with crontab not having the right environment variable or path.
I feel like it's something silly or bush league, but I don't know what.
Any suggentions would be appreciated. It works correctly when I run it from the command line.