LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to run scripts for different users (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-run-scripts-for-different-users-4175499095/)

sryzdn 03-22-2014 10:40 AM

how to run scripts for different users
 
Hi,

Considering the following script:

Quote:

#!/bin/bash
# using the case command
case $USER in
user1 | user2)
echo "Welcome, $USER";;
user3)
echo "This is a testing account";;
user4)
echo "Your account is expiring";;
*)
echo "You’re not allowed here";;
esac
I have added user1-4 and I wanted to run the script for them but I could not. Where should I put the ./script file so that different users can see their messages?

schneidz 03-22-2014 10:42 AM

Code:

su - user -c "command"

sryzdn 03-22-2014 11:00 AM

Quote:

Originally Posted by schneidz (Post 5139301)
Code:

su - user -c "command"

The script I mentioned above is in ./file1, following what you said:

Quote:

su - user1 -c ./file1
-bash: ./file1: No such file or directory

schneidz 03-22-2014 11:03 AM

Quote:

Originally Posted by sryzdn (Post 5139309)
The script I mentioned above is in ./file1, following what you said:

i beleive that since you are switching user, user1 has no idea what directory the previous user was in. try running it with the /full/path/to/file ?

sryzdn 03-22-2014 11:14 AM

I have to put ./file1 somewhere that all user1-4 can see it. That's my question: where should I put it?

schneidz 03-22-2014 11:15 AM

Code:

sudo mkdir -p /whatever/floats/your/boat
#chmod -R 755 /whatever/floats/your/boat



All times are GMT -5. The time now is 02:31 PM.