Score:0

Run commands that run in a shell as a script

in flag

Running the following commands in a shell runs without issues:

ssh user@machine systemctl status my-service.service
ssh user@machine sudo systemctl stop my-service.service
scp -r ./my-service/* user@machine:/home/user/my-service
ssh user@machine chmod +x /home/user/my-service/my-service
ssh user@machine sudo systemctl start my-service.service
ssh user@machine sudo systemctl status my-service.service

However, putting this in a deploy.sh file results in none of the above being able to execute.

Errors:

  • Invalid unit name "my-service" was escaped as "my-service\x0d" (maybe you should use systemd-escape?)
  • Unit my-service\x0d.service could not be found.
  • Invalid unit name "my-service.service" was escaped as "my-service.service\x0d" (maybe you should use systemd-escape?)
  • Failed to stop my-service\x0d.service: Unit my-service.service\x0d.service not loaded. : No such file or directorynlock/
  • chmod: cannot access '/home/user/my-service/my-service'$'\r': No such file or directory
  • Invalid unit name "my-service.service" was escaped as "my-service.service\x0d" (maybe you should use systemd-escape?)
  • Failed to start my-service.service\x0d.service: Unit my-service.service\x0d.service not found. Invalid unit name "my-service.service" was escaped as "my-service.service\x0d" (maybe you should use systemd-escape?)
  • Unit my-service.service\x0d.service could not be found.

Some were broken up. It seems something related to escaping. For some reason adding a space at the end of the lines makes it sort of work but still not without errors.

Googling on the errors shows some hits about using -- and adding it together with the trailing space makes some commands work but still giving an escaping error.

Score:2
cn flag

I would lay dollars to doughnuts that you edited this file on or from a Windows machine.

Linux uses \x0a (ASCII code 10) to separate lines within a file (or script).
Windows uses the combination of \x0d ("Carriage_Return", ASCII code 13) and \x0a ("Line Feed", ASCII 10) to do the same job.

Give a Windows-edited file to a Linux machine and it sees every single line as having an extraneous \x0d on the end.

Get yourself a decent Windows editor (NotePad++ is free and very highly recommended) or learn how to use vi. Sure, it has its own learning curve, but some of its capabilities might surprise you!

in flag
I feel sooo stupid :-) This was it, I edited the file in vscode. Changed from CRLF to LF in the lower right, saved it and it ran without issues.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.