The script runs from command line but crontab fails

后端 未结 3 1157
情歌与酒
情歌与酒 2021-01-24 11:21

I\'m still learning Bash and I\'m having a problem with my script. I want to filter some calls with this script that is analyzing a call log, every 2 minutes as cronjob. The pro

3条回答
  •  鱼传尺愫
    2021-01-24 11:38

    It seems that you are assuming a certain starting directory, and creating a tmp directory there. But when you run it as a cron job, it starts in a different place. So a CD command in your bash startup script might mess you up. You can easily test by using the full path names when you cd or rm or whatever.

    For example,

    if [ -e "tmp/$AYER.lnum" ]; then
        rm /home/username/tmp/${AYER}.*
    fi
    
    # Si existe el archivo con el numero de laultima linea se procesa
    
    if [ -e "/home/username/tmp/$FECHA.lnum" ]; then
    
        # Se lee el numero de la linea y se extrae un archivo con las lineas apartir
        # de la ultima busqueda que se hizo, posteriormente se les hace un grep
    
        while read line
        do
                tail -n +$line $FILE > "/home/username/tmp/$FECHA.hal"
        done < "/home/username/tmp/$FECHA.lnum"
        cd /home/username/tmp
    
        grep -n " 00[0|2-9][0-9]\{4,\}" "/home/username/tmp/$FECHA.hal" > "/home/username/tmp/${FECHA}.new"
    

    and so on.

提交回复
热议问题