Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 9423  / 2 Years ago, thu, january 27, 2022, 9:59:40

I have a small sh script that I use to backup to a remote server. It worked on Ubuntu 16.04 for years, but now on 18.04 it fails. At first I thought it was a problem with anacron, but now I think it is a problem with the script itself or with dash. Here is what is happening:



stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sudo chmod +x rsync-doc-script 
[sudo] Mot de passe de stefan :
stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ ./rsync-doc-script
/bin/sh: 0: Can't open *
stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sh rsync-doc-script
opening connection using: ssh -i /home/stefan/.ssh/id_rsa -l totem MouseHouse rsync --server -vvlogDtprze.iLsfxC . /totembackup/totemdoc (11 args)
ssh: connect to host mousehouse port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]
stefan@stefan-Aspire-F5-573T:/etc/cron.daily$


The error can't open * is preventing the script from running correctly when run by run-parts. Why is this error occurring?



It is not relevant that in the last line, when the script ran, it couldn't establish connection. The server is turned off now.



Here is the script:



#!/bin/sh                                                                                     *
rsync -azvv -e "ssh -i /home/stefan/.ssh/id_rsa" /home/stefan/Documents/ totem@MouseHouse:/totembackup/totemdoc


More From » bash

 Answers
4

I can't tell for sure but it looks like you have a typo on the first line where there's a stray * over to the right.



#!/bin/sh                                                                                     *


^^^ Scroll over to the right to see it.



Example



$ cat script.bash
#!/bin/sh *
echo hi


Run directly:



$ ./script.bash
/bin/sh: *: No such file or directory


Run via sh:



$ sh script.bash
hi


General advice



It's generally advisable to use the exact shell you're expecting with your shebang. If you suspect that you're running into problems where you suspect dash or some other shell is being used, you can always make your shebang explicit by changing it from #!/bin/sh as your shebang #!/bin/bash.



The above is based on your comment below:




but now I think it is a problem with the script itself or with dash.



[#5796] Saturday, January 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
saucdisr

Total Points: 4
Total Questions: 102
Total Answers: 117

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
;