IT_Architect
Verified User
- Joined
- Feb 27, 2006
- Messages
- 1,088
What I need is a way to periodically run a script for each user, as that user.
su - USERNAME -c "COMMAND/SCRIPT"
0 */5 * * * user /home/user/script.sh
#!/bin/sh
cd /usr/local/directadmin/data/users/
for d in * ; do
echo "$d"
done
sudo is an app that you install. I want to use su. I have it working, and am testing scripts before I post.The issue you have with the 'su -c' command is that you start a subshell as the non-priviliged user. 'su' means 'switch user', but you want to use 'sudo' like:
sudo -u youruser "/path/script.sh"
sudo is an app that you install.
su USERNAME -s /bin/bash -c "COMMAND/SCRIPT"