October 29, 201213 yr Not sure how to look this up so I'm looking for some guidance. I've been using midnight commander to copy all my backups onto my server. Because I don't know how/what else do it, I simply pick a directory on my backup drive and copy it to the appropriate share. In windows I would create a batch script to do it, so that I wouldn't have to copy each directory manually. I looked up the "cp" command and I think I've got the syntax that I need to use - cp -rp /mnt/user/usb/backup_UVW/* /mnt/user/Movies My question is how to script that in a batch so they all execute, i.e. cp -rp /mnt/user/usb/backup_UVW/* /mnt/user/Movies cp -rp /mnt/user/usb/backup_XYZ/* /mnt/user/Movies cp -rp /mnt/user/usb/backup_TV1/* /mnt/user/TV cp -rp /mnt/user/usb/backup_TV2/* /mnt/user/TV Any help would be greatly appreciated. Thanks, ~Whip
October 29, 201213 yr Since no one else has jumped in, I will give you a few pointers to get you started down the right path. You have 99% of the work down already! IF your command line instruction worked as you intended, you have the basis for your script. You should probably include the line: #!/bin/bash at the beginning of your script. This will ensure that Bash is used as the shell to run your script. Each command will be run in the order that it appears in the script. You will need to use an Editor which is Linux smart-- vi is one that will work and I know it is a part of the unRAID package. Copy (or retype) your commands into the editor. Now save the file. I would personally use an extension such as .bat but that choice is yours. You will now have to make your file executable. You do this with the chmod command. To run your new script, change to the directory where you have saved it and type the name of the script at the shell prompt. Note that your Telnet session will be unresponsive until the script has finished! I have not included any specific instructions as to how to use either vi or chmod. Google is your friend in this case...
October 29, 201213 yr Author If I'm understanding you correctly, by using what looks like an "include" statement at the beginning (#!/bin/bash) making the file executable - I will be giving that file what it needs to be a batch file (in layman's terms, sorta). Thanks for the help! I do appreciate it. ~Whip
October 29, 201213 yr If I'm understanding you correctly, by using what looks like an "include" statement at the beginning (#!/bin/bash) making the file executable - I will be giving that file what it needs to be a batch file (in layman's terms, sorta). Thanks for the help! I do appreciate it. ~Whip Not quite, as I understand it, the #!/bin/bash statement makes sure that the Bash shell is used to execute the file if the user is using another shell (like the Bourne shell). Not really too likely, but including the statement is a guarantee it will work if your script should go viral! The chmod is the command that is used to actually make the script executable. Otherwise the operating system will simply assume that it is a data file. (Unlike Windows, the extension (.exe, .com, .bat) of a file does not determine if Linux will treat the file as either a data file or a program.) chmod will set a bit in the directory structure that actually makes a file executable. Years ago, one had to run chmod on EVERY file that one wanted to use as a program or batch file to be run. It was just a part of the Unix security system. (Not really sure if that is still true today though...)
October 29, 201213 yr Author Gotcha. I should have said "...statement at the beginning (#!/bin/bash) AND making the file executable..." ~Whip
Archived
This topic is now archived and is closed to further replies.