Ubuntu 16.04 LTS user

Hi guys, I am a newb here and I have been searching these forums and google to no avail. My searches have not found the specific info that I need.

This is personal project of mine to help me get accustomed to setting system jobs and scripts that will run daily/monthly/any time refrence.

I have already (inefficiently) created several folders for the 10-12 users on my Ubuntu machine already where I want this job to go. It is in their home directory in a folder titled 'ulogs'. That is the folder I will be hopefully have the various system wide jobs I create, save files for every user on the system.

I know this job is to be created in cron.daily as a script. I know how frequently I want to run it, perhaps twice a day at some point but will start with once a day right now.

In the script, what is the protocol to save the contents/end result of the job to the folder I've created and selected where I want to save a txt file of job?

For this job, I want to save the contents of the auth.log (the cron script is basically "cat /var/log/auth.log > /home/Users(1-12)/ulogs/daily-signin.txt")

What variables can I use instead of typing out every users username and folder path where the file should be saved.

I'll also want to append the date to the end of the file but I'll figure that out on my own, I can't have you guys doing all the work. I've been searching but I've bounced around from site to site and have not found an efficient way to save the file to every users folder path.

Please help!

1 Answer 1


The following program will create a text file named daily-signin.txt in a directory named ulogs under all users home directory if you run this as root.

for p in `cat "$path"`;
log=`cat /var/log/auth.log`;
mkdir -p /home/$p/ulogs/
echo "$log" >> /home/$p/ulogs/daily-signin.txt

Points to note

  1. The file /path/to/source/file contains the list of users in your machine. If any new user created and you want to get the log file in that user's home directory as well, you have to add the new username in the source.txt file.

  2. As this file is being created on another user's home directory, you will need to run this shell script with sudo privileges

  3. If you are running this script as a cronjob, you may follow this link in order to get this done.

  • I want to thank you for taking time to answer this. I will give this a go and let you know how everything turned out. Another side note, I have a user added to the 'root' group. When I tried to list a users crontab it said ' must be privileged to use -u' after running crontab -e -u <USER>. That account is part of the root group and sudo group. I figured it should have root capabilities. This is a side note, I'll go test out what you posted though. Dec 3, 2017 at 17:59
  • @FinalLuminary Have you tried it ?
    – Rooney
    Dec 4, 2017 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.