Skip to Content

Shell SU Script help

zxeem's picture

Hi friends ,,

I need help .. I am created a very small script for backup in my PC .. but I am Lazy ...

this is the script !

rm -f backupfile.tar.gz & tar -czf backupfile.tar.gz --exclude=backupfile.tar.gz /home/name/ &

it creats .. a backup for my home .. but What i need is to complet the script .. so that it copies it to a restricted writing place that only root can write to .!!

I tried to

echo password > su

but it didn't work .. so if any can help .. I will be so greatful so that I can put this

cp backupfile.tar.gz /mnt/C/ &

zXeem *

Conceptor's picture

Do you want to keep wite acce

Do you want to keep wite access for root only and coping or tar got the privilage to write on your path.or you want to have write access genarlly to your path so every one could write on it

insted of using 2 commands tar then cp you could do it on tar :

Diaa Radwan

ezabi's picture

The --exclude has no place

The --exclude has no place in the context because it's already not in the source directory, the command would be:

Complain, do nothing, get your free Patagonian identity.

zxeem's picture

I am root

OKay . . EveryBody .. I am the root .. but using an ordinary account not the root account !!

what I need is not to know how to backup .. It already works .. with --exclude or without ...

what I really need is when writing a shell script .. that a user runs ... like what I am doing in the backup of my /home/name/ directory ! how to move to root privilige !!

how to use su in the shell script !!


Conceptor's picture


what is the device that mounted on /mnt/C ?

is it windows fat drive or it's windows ntfs drive or it's smb share (windows share) or nfs share (linux share) or it's an ext3 mount drive.

switch to super user (root) then type

go to last line with arrows to the end of file then press "o"

add this line:

press :wq hit enter it will quit.

exit from root shell then try this command

give us the feed back.

Diaa Radwan

Conceptor's picture

i used his command.

i am focusing on it's not important to have tar then cp. i used the same command ,it does not make any sense to exclude non-existing file :)

Diaa Radwan

zxeem's picture

didn't work

this is the ouput I got (after edit visudo ) :

tar: Removing leading `/' from member names

tar: /mnt/c/encback.tar.gz: Cannot open: Permission denied

tar: Error is not recoverable: exiting now


Conceptor's picture

this is not clear

try to send the what we have added on visudo (vi opens /etc/sudoers)

send also the executed command of tar.

Diaa Radwan

zxeem's picture

Here every thing !!!

  1. Host alias specification
  1. User alias specification
  1. Cmnd alias specification
  1. Defaults specification

Defaults targetpw # ask for the password of the target user i.e. root

%users ALL=(ALL) ALL # WARNING! Only use this together with 'Defaults targetpw'!

  1. Runas alias specification
  1. User privilege specification

root ALL=(ALL) ALL

zxeem ALL=(ALL) ALL

zxeem ALL= NOPASSWD: /bin/tar

  1. Uncomment to allow people in group wheel to run all commands
  1. %wheel ALL=(ALL) ALL
  1. Same thing without a password
  1. %wheel ALL=(ALL) NOPASSWD: ALL
  1. Samples
  1. %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
  1. %users localhost=/sbin/shutdown -h now

===================================== about the tar command !!

tar -czf /mnt/c/backup.tar.gz /home/zxeem/

so .. any suggestions !! ...


Conceptor's picture

try it now.

1- remove this line from /etc/sudoers zxeem ALL=(ALL) ALL (you shouldn do ALL) .

2- when you use the full privileged tar command add sudo before it

Diaa Radwan

Pronco's picture

simple bash backup script

-I used to be indecisive .. but now I'm not so sure

zxeem's picture

Nice But ...

That is gr8 .. But I wanna ask .. does it make a backup for a user's home then put it in the /mnt/c ... that only root .. can edit :-|

If so .. then I will be gr8ful if u give me a link to one .. if not .. then hope . u think with us .. to recreat this backup script !!

Thank You


Pronco's picture


with little ease you should be able to modify the script I gave you the URL to do what you want.

just edit the variables in the script to fit in with the directories you want backed up and if necessary you can add in a function to make the backups read-only for all but root.

I've always considered writing my own because I never seem to find one that I consider perfect, the one I gave you is the best one I've found though.

If I ever sit down and write my own script I'll let you know

-I used to be indecisive .. but now I'm not so sure

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Dr. Radut | forum