LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   performing admin task like changing owner of a file through shell script (https://www.linuxquestions.org/questions/linux-newbie-8/performing-admin-task-like-changing-owner-of-a-file-through-shell-script-873130/)

etika 04-05-2011 10:04 AM

performing admin task like changing owner of a file through shell script
 
hey

i want to automate my tasks of administrator using shell scripts
like changing owner of a file which usually only the super user which requires password can change
i want to do this thing using shell script how to do?
please guide me..

zordrak 04-05-2011 10:59 AM

Quote:

man crontab
cron is designed for doing this. Add entries for what you want to schedule in root's crontab and it will do it for you as root.

etika 04-09-2011 06:27 AM

hey
i don't want to schedule my task ,i just want to do once

(i want to change the ownership of a file from tomcat to abc not using sudo but using shell script)

any idea of doing so .. pls tell

etika 04-10-2011 05:17 AM

these are the details of etika.sh
-rw-rw-r--. 1 etika etika 83 2011-04-10 12:05 etika.sh

contents of etika.sh
chown abc:abc /home/etika/Desktop/etika.txt
ls -l /home/etika/Desktop/etika.txt

details of etika.txt file
-rwxrwxrwx. 1 etika etika 83 2011-04-10 12:04 etika.txt

i have made etika as sudoers

now i ran my script
etika@etika Desktop]$ sh etika.sh
chown: changing ownership of `/home/etika/Desktop/etika.txt': Operation not permitted
-rwxrwxrwx. 1 etika etika 83 2011-04-10 12:04 /home/etika/Desktop/etika.txt

i wanted this to happen where abc is also a user on my system
-rwxrwxrwx. 1 abc abc 83 2011-04-10 12:04 /home/etika/Desktop/etika.txt

why its saying operation not permitted i have made etika as a sudoer then why still it is showing problem



even i tried by changing the ownership of etika.sh to root

[etika@etika Desktop]$ sudo chown root:root etika.sh
[sudo] password for etika:
[etika@etika Desktop]$ ls -l etika.sh
-rw-rw-r--. 1 root root 83 2011-04-10 12:05 etika.sh
[etika@etika Desktop]$ sh etika.sh
chown: changing ownership of `/home/etika/Desktop/etika.txt': Operation not permitted
-rwxrwxrwx. 1 etika etika 83 2011-04-10 12:04 /home/etika/Desktop/etika.txt

still there is a problem


i hope i have stated my problem clearly


(
i will be running this script from jsp page through tomcat and i want my script to change the ownership of my file etika.txt which is owned by tomcat to etika user .... but all this ownership changing work is done by root iam unable to change the ownership of the file)

TobiSGD 04-10-2011 05:25 AM

Just putting a user into a sudoers-file isn't enough, you also have to start your script via sudo
Code:

sudo etika.sh


All times are GMT -5. The time now is 10:51 PM.