0

So I am trying to create a script that will backup my plex data. I am new to writing bash shell scripts and unsure what to do. This is the following script:

#!/bin/bash
sudo service plexmediaserver stop
sudo zip -r plexbackup.zip /plexdata
mv /media/usb2/plexbackup.zip /media/usb1
sudo service plexmediaserver start

Everything works fine when I manually input each line of code into the terminal. But when executing the bash script, I get the following error.

pi@raspberrypi:/media/usb1 $ bash plexBackup.sh
plexmediaserver: unrecognized service
        zip warning: name not matched: /plexdata

)ip error: Nothing to do! (try: zip -r plexbackup.zip . -i /plexdata
plexmediaserver: unrecognized service
mv: cannot stat '/media/usb2/plexbackup.zip': No such file or directory

My questions are the following:

  • When I turn off and on the plex server in the terminal, it recognizes it, but why not in the bash script?
  • The directory path I point to when zipping the file is correct; however, I get an error saying it doesn't recognize it.

I have looked at instructions online for writing bash scripts, but mostly find ones for echo commands and not for modifying Linux directories.

I ran a compiler command sudo chmod +x plexBackup.sh and it seemed to sorta work. It recognized the directory I was pointing to, but not the plex servers.

  • What would a non-automated batch script look like? :) – Charles Duffy Nov 07 '22 at 21:07
  • Seriously, though, your problem here is CRLFs; your file is saved in DOS/Windows format. You can tell by the cursor going back to the front of the line when it shouldn't; that's caused by a carriage return being printed to the screen. – Charles Duffy Nov 07 '22 at 21:07
  • (btw, no, `chmod` is not a compiler; it just changes filesystem permissions, nothing else; `chmod +x` is setting the execute permission). – Charles Duffy Nov 07 '22 at 21:08

0 Answers0