I have two scripts, owned by root.
#!/bin/sh
#script1.sh
echo "all: first" > my_makefile
echo >> my_makefile
echo "first: " >> my_makefile
echo "\ttouch file.txt" >> my_makefile
#!/bin/sh
#script2.sh
while true
do
make -f my_makefile
sleep 10
done
script2.sh is called as “sudo sh script.sh” and continually runs make on my_makefile. script1.sh is called by individual users to alter the makefile.
How can I run the makefile command so that the file.txt is owned by the user, rather than root?
Sorry, I wasn’t using sudo correctly. I just needed to replace the last line of script2.sh with: