Curl request from cron job is not working,but works manually

5,086

Add a shebang line and explicitly use bash (on Ubuntu /bin/sh links to dash).

#!/usr/bin/env bash

or

#!/bin/bash

The first will search the environment for bash.

Share:
5,086

Related videos on Youtube

cafebabe1991
Author by

cafebabe1991

Updated on September 18, 2022

Comments

  • cafebabe1991
    cafebabe1991 almost 2 years

    I have a cron job that runs every minute and makes a curl request and i have verified that using grep on the syslogs.

    But the curl is not happening somehow and moreover i have a small echo statement in the cron that i log in some file.Even that log is not printing but manually when run my shell file it works.

    Can someone help me out in this.?

    Update : This is the shell file i am using

    #This file sends the changed files to our server
    #var=$(ls ~/Downloads | grep -v "^d")
    #files=""
    #for f in $(ls ~/OurDrive | grep -v ^d)
    #       do
    #               
    #               files+="$f"","
    #               
    #       done 
    files=()
    
    cd /home/user/OurDrive
    for file in *; do
        [[ -d $file ]] && continue
        files+=( "$file" )
    done
    
    
    comma_separated=$(IFS=,; echo "${files[*]}")
    echo "$comma_separated" 
    curl --data "file_list=$comma_separated&username=${USER}" http://localhost:8084/url/add.do
    echo "done"> /home/user/Desktop/log.txt
    
  • jobin
    jobin about 10 years
    /bin/sh links to dash? How come?
  • Elliott Frisch
    Elliott Frisch about 10 years
    @Jobin Click the link labeled dash.