Ethical Hacking and Penetration Testing Guide


nano :  file editor vi



Yüklə 22,44 Mb.
Pdf görüntüsü
səhifə31/235
tarix07.08.2023
ölçüsü22,44 Mb.
#138846
1   ...   27   28   29   30   31   32   33   34   ...   235
Ethical Hacking and Penetration Testing Guide ( PDFDrive )

nano

file editor
vi

vim file editor
free -h

check free memoryruns.
Linux Scheduler (Cron Job)
Cron is a utility that helps us create schedule to perform a certain task/command. As we know that 
/etc having configuration files for most of the services same as for cron.
We will just go through a quick review of how does it work and how do we set it up.
The following is the hierarchy for it.
# * * * * * command to execute























└─────
day of week (0–6) (0–6 are Sunday to Saturday,
or use names; 0 is Sunday)




└──────────
month (1–12)



└───────────────
day of month (1–31)


└────────────────────
hour (0–23)

└─────────────────────────
min (0–59)
It’s pretty simple and easy to understand; aforementioned hierarchy is self-explanatory. 
First * represent min 0-59 
Second * represent hour 0-23
Third * represent day of month 1-31
Forth * represent month 1-12
Fifth * represent day of week 0-6


26
◾ 
Ethical Hacking and Penetration Testing Guide
Cron Permission
Two files play important role in cron.
Cron Permission
Two files play important role in cron.
cron.allow
cron.deny
If these files exist, then they impose some restriction accordingly on users. That is, if a user is in deny 
list, so he/she won’t be able to schedule any job/task and if user is in allowed list then she/he will be 
able to add schedule job/task. All we have to do is just add user name in either of these two files.
Cron Files
Cron.daily
Cron.hourly
Cron.weekly
Cron.monthly
/etc/crontab: system-wide crontab
root@net:~#cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don’t have to run the 'crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.monthly )
This is the output for crontab file; in other words, 
cron.hourly , cron.daily , cron.
weekly , cron.monthly
are symlink of crontab.
Let’s say I would like to run a schedule at 12Am daily basis .
root@net:~#vi /etc/cron.daily/logs
0 0 * * * /home/network/log.pl
Save and exit.


Linux Basics
◾ 
27
Execute a job in every 5 seconds
Cron does not provide this feature by default. For this, we need to write up a small bash script 
to accomplish this task by using the “sleep” command
cat seconds.sh
#!/bin/bash
while true
do
/home/cron/seconds.sh
sleep 5
done
root@net:~#chmod +x seconds.sh
root@net:~#nohup ./seconds.sh &
This command will exit if any error occurred and & signed will put the process in background.
Execute a job in every 4 minutes
If we specify * in the first field, it will run in every minute, it is not the way we want it so we 
need to add */4 in the along with asterisk. If you wish to run in every 30 min, just add */30
root@net:~#vi cron.daily/logs-min
*/4 * * * * /home/network/log-min.pl
Save and exit.
Execute a job in every 4 hours
If we specify * in the second field, it will run in every hour; this is not what we want it, so we 
need to add */4 along with asterisk. If you wish to run in every 15 hours, just add */15
root@net:~#vi cron.hourly/logs-hour
* */4 * * * /home/network/log-hourly.pl
Save and exit.
Execute a job in every 4th weekdays
The fifth field is DOW (day of the week). If we specify * in the fifth field, it will run in every 
day. So we need to specify the specific day on which we want to run schedule. In the example, we 
want to run schedule on every Thursday.
root@net:~#vi cron.week/logs-week
* * * * 4 /home/network/log-week.pl
OR
* * * * Thu /home/network/log-week.pl
Save and exit.
Execute a job in every 4 months


28
◾ 
Ethical Hacking and Penetration Testing Guide
The third field is DOM (day of the month). If we specify * in the third field, it will run in 
every day of month. So we need to specify the specific day on which we want to run schedule. The 
fourth field is for month; If we specify * in the fourth field, it will run in every month. So we need 
to specify the specific day and month on which we want to run schedule. In the example, we want 
to run schedule on every first day of oct.
root@net:~#vi cron.week/logs-week
* * 1 4 * /home/network/log-month.pl
OR
* * 1 apr * /home/network/log-month.pl
Save and exit.
Note: If you want to assign a range like Jan to Nov then you will need to specify month as 1–11 .

Yüklə 22,44 Mb.

Dostları ilə paylaş:
1   ...   27   28   29   30   31   32   33   34   ...   235




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin