Crontab Tutorial - VPS with AWS EC2 and Python Intro to AWS

sentdex · Beginner ·☁️ DevOps & Cloud ·12y ago

Key Takeaways

Sets up a crontab to run scheduled tasks on AWS EC2 and Python

Full Transcript

hey guys welcome to your fourth AWS or really just any VPS web server tutorial where we left off showing you guys how to do you know run some of your Python scripts but now what I want to do is show you the cron tab and then probably in the coming videos show you how to run those Python scripts 1 run them run them simultaneously in the background and then also finally run them without hanging up when you log out your user so with that let's go ahead and get started the first thing we want to show you is the crontab the idea of the crontab is to run scheduled jobs it's or you call it most people call them cron jobs right so we're gonna go into the cron tab again you can get in there either with just a simple crontab dashi and you can use the default editor or you can just change or specify that your editor you want is Nano and we want to enter the crontab with the intention to edit it so here's our Kuran tab it's totally empty so how do we even set up a cron which pran will be on each line for one and to set up a cron the default is just five asterisks separated by a space and each asterisk has a meaning to it so this first star represents minutes so you can give it a value of 0 to 59 the second star represents hours again 0 to 23 the next star represents the day of the month so 1 to 31 the next star is gonna represent the actual month and this is gonna be a 1 to a 12 don't confuse that with a 0 2 and 11 because the other ones were giving us zero ideas subsequently you then have day of the week so this is going to be again a 0 to a 6 so kind of confusing the way they force you to do that but that's how it's done now the next thing is like say ok this is our minute so if we say and then you basically put your parameter on the other side of it right so let's say you wanted to run everything at the half hour you would just do this you would put it you've got the star there and the 30 right and I'm not quite sure I guess this because I got highlighted anyway star 30 that will run this cron that doesn't there's no nothing those specifications here but that would run this every happen every hour at the 30 so this will run every hour at the 30 minutes after the hour right if you wanted to run a cron every 30 minutes it would do a slash 30 and that will run it every 30 minutes conversely you could do something like this and run the cron every three minutes or if you did this it would run the cron at every third minute after the hour so let's say we want to leave it as every every one minute we wanted to run this cron same thing goes for all of these so like if you wanted to run a cron at one every day that's how you would do it subsequently if you wanted to run it every one hours you would do it this way although this full cron is really every one hour in one minute the Quran will run now in our case since we're mostly interested in doing Python scripts you're going to want to perceive this the script with what you want to run it with and you can either do it this way like user boom and Python writes s pythons location here but you can cut you can always treat these things at least for my phone you can always treat them just like it's at the line itself so you can most likely call Python and then the script so we could say example dot PI right and it will run this script at every one minute in one hour now I'm gonna go over here and actually will probably come in here and redo it since this file doesn't exist we'll go ahead and create the file it'll be the first thing we do so I'm gonna go ahead and exit out of here and I'm just going to say no to not save the changes so not CD back a couple of directories and let's make sure we're there and now we want to see the Ben and if we list out everything that's in let's see no so CP LS what we really wanted was first user yeah so CD in the user or USR I'm not sure that stands for user but that's what I say and then CD in the bin LS and now you should see here's where python is and you even got Python 26 and 2.6 and all that so anyway see the back out again see the home slash I think we're ec2 - user right I'm user okay so we have nothing here so let's go ahead and make our example of Python file so let's go nan-oh I guess we'll do running one dot pi first and we're gonna go ahead and import time and then we're gonna make our function and this is just going to be three tests one and it's gonna sleep for one second then it's gonna go ahead and call that function exit save yes good now I want to make a second version of this file so I can show you guys like simultaneous running so we've either a redo this or we can use a function that I didn't teach you guys yet and that's the copy so to copy something you do CP what do you want to copy well we want to copy running one dot pi and then what do you want to copy it to in this case I want to copy it to running to dot pot right so you do that it's copied we can LS and we can see okay yeah we've got gum both running at the moment now just for kicks I want to see if I can do you surf and python running one pi yeah okay so so you should be able to and we should probably make these loop as well anyway so you can either put out the full path like this will accept the full path where I or you could just straight say Python and that's for that for that cron so you can give the pole path like sometimes you might need to but yeah you can usually treat that crime it's it's like it's it's like you're using that user so each user is going to have his own little crontab right so as long as he's got the permissions to run it'll run just like it's he's typing in the line anyway I guess what we'll do is we'll quickly edit these these files here at least running one and we're going to just throw this in a Wow true loop here shift that over XE yes oh and I don't think it yeah we put the sleeper in the function so now when we go python running one time it's gonna run that script but if you'll see the only way we like if we tried any as hard as we could Python there actually was sorry I want to do yeah Python running to dot hi you just can't get it in there right so you'd have to click you know keyboard interrupt of the script and then you would have to call python running to dot pi and that's all fine and dandy you know we need to make python run into nano running to we want to have this one say test too so we can identify what's running okay so anyway so that was just the crontab basics we made these two files that we want want to run simultaneously and we see that we're having quite the hard time doing it so the next video I'm gonna be showing you guys how you can get them to actually run simultaneously so anyway stay tuned for that video as always thanks for watching thanks for the support in the subscriptions and until next time

Original Description

Playlist for this series: https://www.youtube.com/playlist?list=PLQVvvaa0QuDerJ6zgyBIsJZMk8w4hZb1A This video covers the basics of how to set up a crontab to run scheduled tasks (cron jobs). This series introduces you to the AWS EC2 service for use with python elastic computing in the cloud. Sentdex.com Facebook.com/sentdex Twitter.com/sentdex
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related AI Lessons

5 Best BrowserStack Alternatives to Optimize Your Testing Infrastructure
Discover the top 5 BrowserStack alternatives to optimize testing infrastructure for better execution speed, pricing, and test management
Medium · DevOps
`wrangler dev --remote` silently writes to your production KV namespace — here's the fix
Learn how to safely use wrangler dev --remote with live KV namespaces without overwriting production data
Dev.to · 강해수
Qwen 3.6 27B Is the Local Dev Sweet Spot — Here's Why
Discover why Qwen 3.6 27B is the ideal choice for local development, and how it can boost your productivity
Dev.to · Carter May
Deploying Spring Petclinic Microservices with Docker Compose: An End-to-End DevOps Deployment Experience
Learn to deploy Spring Petclinic microservices with Docker Compose for a seamless DevOps experience
Dev.to · Nice Nwogu
Up next
Containers on Amazon ECS with Mama J
AWS Developers
Watch →