#!/bin/bash
while read -r line; do
mkdir "UNIX/$line"
done < usernames.lnk
MasterDir="/home/darkeve/Documents/OS/master/"
USERHOME="/home/darkeve/Documents/OS/UNIX"
for FILENAME in `cat $MasterFile`
do
cp $MasterDir/$FILENAME $USERHOME/$USER
done
My script does the first job right, it first reads a file called “usernames” and creates individual folders for each user into the UNIX folder. But it is then supposed to copy 3 files from the master folder called “file1, file2 and file3” and copy them into each individual user folder in the UNIX folder but it simply doesn’t do that. Any help would be appreciated.
p.s. I am very new to scripting so please keep it simple.
Your current script uses $USER in cp command, which is ‘user running the script’ and not read from usernames.lnk. If you want to copy to each individual folder you need to put for-loop inside first while loop and use $line as destination folder name, like this:
It’s usually a good idea to simply echo things when you are not sure what goes wrong, you can try e.g.
and so on to see the difference on these variables.
Also, $MasterFile is not defined in your script. It should be introduced same way than MasterDir and USERHOME in the beginning.
Edit: I added it in the script example, please change it to correspond with your file.