![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Calling expect scripts from other expect scripts | seva | Shell Programming and Scripting | 0 | 04-03-2008 10:45 AM |
| FTP Scripts | raghav1982 | Shell Programming and Scripting | 27 | 12-07-2007 03:38 AM |
| use of ssh in scripts | esham | Shell Programming and Scripting | 7 | 11-16-2005 08:27 AM |
| Help with GDL to SQL scripts | ch4r1e5 | Shell Programming and Scripting | 0 | 10-31-2005 02:51 PM |
| using su in scripts | uchachra | UNIX for Dummies Questions & Answers | 3 | 03-11-2002 10:24 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm looking to write a .sh script that will allow me, from my home, directory to list and remove *.lst and *.bad *.dat files owned by user 1 (easy enough!). I then need to su to user 2 so that I have permissions to remove the *.lst *.log and *.bad files from user 2 home directory. I have superuser privilages if it can be done through root.
Any ideas/script examples would be appreciated. Thanks in advance. Soots |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Since you have superuser privileges you do not need to do any sort of 'su'. Root automatically has the rights to remove files from any and all directories (regardless of the ownerships).
|
|
#3
|
|||
|
|||
|
Well, generally speaking, if you want to run as a command as another user, you don't use su, but sudo. Read it's man page--pretty easy to use. But you will be prompted for the user's password (though only one time, so that you can do a bunch of sudo commands before having the time period run out and you have to retype the password.) Prompting for the password means that you can't run your script as cronjobs. Else you have to store the password in some file, which is nt safe.
|
|
#4
|
||||
|
||||
|
Quote:
Last edited by reborg; 08-12-2005 at 05:21 PM. |
|
#5
|
|||
|
|||
|
If you have root:
su - user1 -c "rm *.lst *.bad *.dat" su - user2 -c "rm *.lst *.bad *.dat"
__________________
[url=http://chuckb.1le.net/]My website[/url] |
|
#6
|
|||
|
|||
|
I have tried above script
actually i want to remove some files which in owned by root dir. so i have written my script like this su -xxxx -c "rm *.dat" where xxx is root password. but the error user xxx does n't exist was coming. please help regards rajan |
|
#7
|
|||
|
|||
|
"su -xxxx -c "rm *.dat"
where xxx is root password. but the error user xxx does n't exist was coming." The above is incorrect syntax, here is the correct: su - useryouwantobe -c "rm *.dat" Notice the space between "su - " and username. If you are running this as root then u won't be prompted for a password, but if not then you will be prompted for the password of the user u are switching to. imo, use sudo. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|