0

I have a script that does a ssh connection to a Ubuntu machine to get a file and store it on my raspberry pi. If I execute the script manually, in shell it works perfectly how I want it but in crontab -e it doesn't work. I also have another script in crontab that I also start with @reboot and this script works perfectly fine on reboot. I assume that the script is getting executed without the network being up but I don't know how to work around it.

This is my crontab -e :

@reboot bash /home/pi/skript/conf.sh
@reboot node /home/pi/node/buttonled.js

and this my script:

#!/bin/bash
file=`(ssh davy@192.168.0.15 ls -t /home/davy/rundgaenge | head -1)` 2>/home/pi/skriptfehlermeldung.txt
scp davy@192.168.0.15:/home/davy/rundgaenge/$file /home/pi/rundgangConf/
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • You [should not use `ls` in scripts](http://mywiki.wooledge.org/ParsingLs) and there are various other common issues here which http://shellcheck.net/ can diagnose. Maybe try that before asking for human assistance. – tripleee Apr 16 '19 at 16:13
  • The parentheses in the subshell are unnecessary and somewhat distracting; I thought they were a syntax error at first. – tripleee Apr 16 '19 at 16:14
  • well the script does work from the command line... – Davy Pereira Apr 16 '19 at 16:16
  • Using `.sh` in the name of a `node` script is so odd it's tempting to say it's wrong. – tripleee Apr 16 '19 at 16:17
  • oh yeah you're right I actually have it as .js but I typed it wrong my fault, sorry – Davy Pereira Apr 16 '19 at 16:20
  • I spellchecked my script on shellcheck.net with $() and now it says that it detects no issues so I would say that my script is working fine.. – Davy Pereira Apr 16 '19 at 16:25
  • 2
    What does your `skriptfehlermeldung.txt` say? – that other guy Apr 16 '19 at 16:42
  • You should also have received a warning for the [missing quotes](/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) but if you fixed that too, all good. (The extra parentheses are still unnecessary and slightly inefficient.) – tripleee Apr 16 '19 at 16:55
  • 1
    My uninformed guess is that the network is fine but `cron` lacks access tn the `ssh` key. – tripleee Apr 16 '19 at 16:57
  • Does cron email you any job output? If not, you could try adding something like this to the top of your script: `exec 1>>/var/tmp/script.log 2>&1; date; set -x;` and see what it produces – jhnc Apr 16 '19 at 17:54

0 Answers0