You are not logged in.
Pages: 1
Hello all :]
I'm trying to make a script to automatically creates a new, blank scripting file..
Here's my code:
#!/bin/bash
#email@email.com
#Adam
read -p "Please input a name for the script: " nm
if
[[ "$nm" == "$nm" && "$nm" != "exit" && "$nm" != "" && "$nm" != "quit" && "$nm" != "q" ]]
then
touch ~/scripts/"$nm"
echo "#!/bin/bash" >> ~/scripts/"$nm"
echo "#email@email.com" >> ~/scripts/"$nm"
echo "#Adam" >> ~/scripts/"$nm"
su root -c "chmod a+x ~/scripts/"$nm" && exit"
elif
[[ "$nm" == "exit" || "$nm" == "" || "$nm" == "quit" || "$nm" == "q" ]]
then
echo "Exiting"
sleep 1
exit
fiWhat I want it to do is also have the script to set its permissions to make it executable, though to do this I need to have it access root. I figured that part out, but the problem is that I can't figure out how to have it automatically set the home directory to the user that started the script when the script gets elevated to root. I really want the script to be universal for I can run it as any user without needing to constantly change the script to add in the current users home directory.
Last edited by muffinss (2011-11-03 09:13:14)
Offline
Well why don't you do run a whoami and save it as a variable then use that?
name=`whoami`
...
/home/"$name"/scriptsAre you sure you need root priviledges to set the executable bit? The script is being saved in the users own home folder it should be possible for them to set +x in their own home folder.
Offline
Pages: 1