LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-22-2014, 10:40 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 274

Rep: Reputation: 9
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?
 
Old 03-22-2014, 10:42 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
su - user -c "command"
 
Old 03-22-2014, 11:00 AM   #3
sryzdn
Member
 
Registered: Feb 2013
Posts: 274

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by schneidz View Post
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
 
Old 03-22-2014, 11:03 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by sryzdn View Post
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 ?
 
Old 03-22-2014, 11:14 AM   #5
sryzdn
Member
 
Registered: Feb 2013
Posts: 274

Original Poster
Rep: Reputation: 9
I have to put ./file1 somewhere that all user1-4 can see it. That's my question: where should I put it?
 
Old 03-22-2014, 11:15 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
sudo mkdir -p /whatever/floats/your/boat
#chmod -R 755 /whatever/floats/your/boat

Last edited by schneidz; 03-22-2014 at 11:18 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Log-in Scripts for Existing and New Users devUnix Linux - General 2 12-23-2013 03:39 PM
[SOLVED] Best folder to put scripts to be run by cron as various users anon091 Linux - Newbie 12 03-20-2013 02:32 PM
How to run fsck during a shutdown sequence, or how to run one-time init scripts? bgoodr Debian 5 11-28-2010 03:08 PM
setkeycodes for users/ath0 scripts delta3 Linux - General 0 05-24-2004 12:54 AM
cannot run scripts unless su odious1 Linux - General 5 07-19-2003 12:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration