Script to copy specific directory based on variable to folder with that variable name
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Script to copy specific directory based on variable to folder with that variable name
So this is what I want the script to do.
I plug in a usb harddrive, I mount the drive manually.
I want the variable to be a username.
Then the script copies these files after making the directory for the user
mkdir /home/usrbak/username
cp -rfn /media/Disk/Documents\ and\ Settings/username/Favorites /home/usrbak/username
cp -rfn /media/Disk/Documents\ and\ Settings/username/Desktop /home/usrbak/username
cp -rfn /media/Disk/Documents\ and\ Settings/username/My\ Documents/ /home/usrbak/username
cp -rfn /media/Disk/Documents\ and\ Settings/username/Local\ Settings\Application/ Data\Microsoft\Outlook\*.pst /home/usrbak/username
and that's it. So the script really only needs me to answer two questions, #1 what is the name of the mount, and #2 what is the name of the user. So those are variables, anyone have a simple tutorial for a script like this? I even might automate the mounting of the disk as well.
it errors on the 2nd line, cannot create directory, as it doesn't seem to input variable 1. This is after I removed the -p, which gives a command not found error instead.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.