# Shell scripting

**URL:** <https://community.unix.com/t/shell-scripting/156955>\
**Category:** Shell Programming and Scripting\
**Created:** [October 24, 2005, 8:26am UTC](https://community.unix.com/t/shell-scripting/156955 "2005-10-24T08:26:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dipanrc](https://community.unix.com/letter_avatar/dipanrc/32/6_22734026db12803ebb3e059622ac3534.png) [@dipanrc](https://community.unix.com/u/dipanrc)\
**Post date:** [October 24, 2005, 8:26am UTC](https://community.unix.com/t/shell-scripting/156955/1 "2005-10-24T08:26:34Z")

</div>

Hi friends I am new in this forum....

I am currently working as a Linux Admin in a company.....

Currently i have faced a problem,if u help me that will great for me..

I need a little guidence 2 create a shell script which will

automatically changes 2 a specific user (just using "SU") according 2 me ,

then enter into a specifc directory and execute a executable file....

This should be completely time dependent and automatic.........

---

<div class="post-metadata">

**Author:** ![Unbeliever](https://community.unix.com/letter_avatar/unbeliever/32/6_22734026db12803ebb3e059622ac3534.png) [@Unbeliever](https://community.unix.com/u/Unbeliever)\
**Post date:** [October 24, 2005, 10:09am UTC](https://community.unix.com/t/shell-scripting/156955/2 "2005-10-24T10:09:08Z")

</div>

Really need a little more information. Is the script run as root? Is it the same executable file in each directory changed to? if not how do you know what executable to run?

Out of interest, if it is \*not\* run as root then it can only be done in a totally insecure way unless you use sudo or something.

Unbeliever

---

<div class="post-metadata">

**Author:** ![Unbeliever](https://community.unix.com/letter_avatar/unbeliever/32/6_22734026db12803ebb3e059622ac3534.png) [@Unbeliever](https://community.unix.com/u/Unbeliever)\
**Post date:** [October 26, 2005, 11:19am UTC](https://community.unix.com/t/shell-scripting/156955/3 "2005-10-26T11:19:26Z")

</div>

Thanks for the info in the PM.

Root can run scripts as different users using 'su -c \<username\>'

So you could be doing something like.

```nohighlight
for user in <user list>
do
   cd <relevant directory>
  su -c $user <command>
done

```

---

<div class="post-metadata">

**Author:** ![rajan\_ka1](https://community.unix.com/letter_avatar/rajan_ka1/32/6_22734026db12803ebb3e059622ac3534.png) [@rajan\_ka1](https://community.unix.com/u/rajan_ka1)\
**Post date:** [October 27, 2005, 3:27am UTC](https://community.unix.com/t/shell-scripting/156955/4 "2005-10-27T03:27:31Z")

</div>

I have tried with our code

i have given

su -c root in shellscript  
but the error

standard in must be a tty  
rm: cannot unlink `TIP-14-3000434.tip': Operation not permitted

was coming

please help

regards  
rajan

---

<div class="post-metadata">

**Author:** ![Unbeliever](https://community.unix.com/letter_avatar/unbeliever/32/6_22734026db12803ebb3e059622ac3534.png) [@Unbeliever](https://community.unix.com/u/Unbeliever)\
**Post date:** [October 27, 2005, 3:53am UTC](https://community.unix.com/t/shell-scripting/156955/5 "2005-10-27T03:53:21Z")

</div>

'su -c' is just a construct for running a command as another user. It looks like the program you are running is having problems running under cron or something similar. I've never actually seen either of the errors you mention.

I would try searching for them in google and see what turns up. Remember that when you 'su -c \<command' the command is being run as that user and so many operations that would succeed as root may fail.
