S
S
SquareWheel2015-12-17 19:33:57
bash
SquareWheel, 2015-12-17 19:33:57

How to run a bash script passing a parameter at startup?

I'm not sure how clear I expressed the problem in the title .., but you need to run the script as follows
./skript.sh user
Where user is the value of the variable that determines which user will run some script commands.
And since it must be run from cron - read, not an option. whoami - too, because users are different.
Can you please tell me if this is possible at all, and if so, how? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
abcd0x00, 2015-12-18
@SquareWheel

If you need to separate commands (one from one user, others from another), then you can use sudo inside the script.
Script

#!/bin/bash

user=${1:-guest}

whoami
sudo -u "$user" whoami

exit 0

Call
[[email protected] sh]$ ./t.sh guest
guest
guest
[[email protected] sh]$ ./t.sh apache
guest
apache
[[email protected] sh]$

M
mureevms, 2015-12-17
@mureevms

And since it should be run from cron

Have you ever seen the crontab file?
where user is the username from which to run the script.
Well, in extreme cases, through sudo you can:
sudo -u user /home/script.sh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question