-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to be able to run cron jobs on the user level #5
Comments
Looks good, just remember it is more so how to organize scripts in the user cron job folder or whatever way this is setup at user level. I am particularly curious if the only way to set a script on a cron is by dragging to special folders or if there are other metaphors we can use. |
for personal reference: some best practices I'm able to run cron jobs on my computer as root and as my user both. Also, we can specify what scripts to use rather than dropping scripts into the |
Running cron jobs at the user levelWe can run cron jobs at the user level using two different methods:
In our case, the former seems like a good option, however both methods will be covered. This is a high level overview to get us started, but more info can be found on the official Ubuntu page. Some pointers on best practices can be found here as well. Specifying the user that executes a cron task in the system crontab fileFirst, open the contents of the system crontab file using a text editor. It will be located at The contents of the file should look just like this:
To better understand how the timings work, see "Crontab Lines" section here. Let's examine the following line from the crontab file: The first 5 columns say that the command located in the last column will execute the files in We can add more lines following the exact same format. Specify the time(s) when you want the command to execute as a desired user. In order to run python scripts, the python scripts themselves must contain
The above line translates to running the file Placing scripts into the Setting up a user specific crontab fileSetting up a specific user crontab consists of the following steps:
Checking to see if your cron job ranThere are several ways to confirm if your cron job has run.
Other NotesWhen we have tasks that should be executed by a specific user, it is recommended to create said user, and specify it in the system crontab file. If a command is too long to execute, it should be placed in a script file instead of cluttering the crontab file. |
Did you try running any of the variants in our server as a test run? Could be some 2 line script appending a timestamp of the current time to a .txt file. |
@carlosparadis , not yet i will give that a try now |
That would be great. It is also a nice test run to see if it works without sudo, given you don't have sudo access yet in sea-vm. Keep an eye on the possibilities on choosing the time resolution to run the scripts (i.e. if we can choose every hour, every minute, etc and if we can freely choose whatever we prefer). |
The user specific crontab method mentioned above works fine on the IT-VM. I created my own crontab using
The python script ran on the hour. (as you suggested, I got the current time and appended the current time to a text file). And as for the first method (system crontab file), you can try to test it out later since you have write permissions to edit
Yes, we can choose when to run the script. All we need to do is specify it in the first five columns. It does not need to be strictly on the minute, hour, day, etc. By putting |
Wouldn't |
notes from meeting 10/12/17:
|
Now that we understand cron jobs, the next step is to have a user that will be:
Step 1: Creating a "non-user" type userWith sudo permissions, run the following commands:
Step 2: Checking that the user was created properlyEnter the following command:
The output should resemble this:
The last field delimited by A home directory is listed, however typing Next, enter the following command:
The output should resemble this:
The second field after contains an encrypted password (i had set no up earlier), however this second field needs to begin with Finally, try to log into that account you just made with the following command:
The output should look like this:
Now enter the command: It should return YOUR username and not the one we just created. We were not able to effectively log in because 1. the password is locked, and 2. the shell is disabled... Step 3: Running scripts as this userNow that the user is set up, we can run scripts as that user by specifying that in the crontab file located at Because the user has no home folder, you MUST give the appropriate permissions to the files and directories which the user will interact with or else the cron job won't run. (The user does not have permissions outside of its home, which we know has no home..) See this guide for an in depth guide on how to do this but TLDR:
notesReasoning behind this usage pattern comes from this post. @carlosparadis, I think you mentioned at our previous conference call 10/12 that you and Justin would meet in person at some point to discuss stuff related to user accounts. Maybe double check with him to see if he has any insight into this or suggestions. Also could you give me access to this repo? I think some of the stuff here and in #3 could be placed in a wiki to be referenced quicker. |
postgres backup script located at: |
|
yeah, its in the comments which will be in the wiki soon
I did that on my computer, but had to update the permissions in my database to accomodate the new user. So, before I do anything to the IT-VM database kiosk table, I'm taking some time to understand Postgres permissions/users etc.
i looked into it. when you get the chance, take a look at my comment in #3 |
Investigate:
The text was updated successfully, but these errors were encountered: