18th Day-linux System scheduled task Crond in-depth combat

Source: Internet
Author: User

Jane Answer:
1, every 1 minutes, print a + number to Oldboy.log, please give crontab complete command.
Answer:
#printf + every Minute
* * * * * echo ' + ' >>/oldboy.log

2./etc/services files are packaged and backed up to/tmp every 2 hours (preferably each backed up into a different backup package).
Answer:
(1) on the command line test
[Email protected]:~# ll/etc/services
-rw-r--r--1 root root 19605 October 2014/etc/services
[Email protected]:~# cd/etc/
[Email protected]:/etc# tar zcvf/tmp/services_$ (date +%f-%h). tar.gz./services
./services


(2) Scripting:
vim/server/scripts/tar.sh
#every hour tar/services to TMP
cd/etc/
Tar zcf/tmp/services_$ (date +%f-%h). tar.gz./services
(3) Writing CRONTAB-E
#every hour tar/etc/services to TMP
XX */2 * * */bin/sh/server/scripts/tar.sh >/dev/null 2>&1
Skills:
1, the command line test good, the specification script to store the path.
2, Scheduled tasks to pack or handle other work, not on the screen output, can be large to the log file.
3, from the scheduled task to the script of the project as far as possible to copy, to prevent the re-knock wrong.

1,/bin/sh/server/scripts/tar.sh to copy, do not hand knock.
2, execute the script to call/bin/sh
3, end directed to empty, >/dev/null 2>&1

3, every night 12 o'clock, packaging site Directory/var/www/html backup to the/data directory (preferably each backup by time to generate a different backup package).
Answer:
To view the script:
Cat tar.site.sh
Cd/var/www && tar zcfp/data/html_$ (date +%y%m%d). tar.gz./html
Scheduled tasks:
# #tar/var/www/html by Shell Scrpt by Oldboy at 20121213
XX * * * */bin/sh/server/scripts/tar_site.sh >/dev/null 2>&1

4, every week Six 9:00 and 14:00 to the old boys here to learn (the implementation of the program/server/script/oldboy.sh instead of learning).
Answer:
# #study from Oldboy at 9:00am and on Sat and sun
XX 9,14 * * 6,7/bin/sh/server/script/oldboy.sh >/dev/null 2>&1
5, please describe the following path content is what?
/etc/sysctl.conf and System kernel optimizations
/etc/rc.local configuration file for boot task
/etc/hosts Domain name parsing file
/etc/fstab automatically mount all partition profiles when the system is powered on
/var/log/secure system security log, record the user log on the computer information
11, add a user Oldboy, and specify that the SA group, the group ID 801,UID is 808, and do not create a home directory and prohibit its landing.
Answer:
Groupadd-g 801 SA
USERADD-G sa-u 808 oldboy-m-s/sbin/nologin
[Email protected]:~$ useradd--help
Usage: useradd [options] Login
Useradd-d
useradd-d [Options]

Options:
-B,--base-dir base_dir The base directory of the new account's home directory
-C,--comment comment new account GECOS field
-D,--home-dir home_dir the home directory of the new account
-D,--defaults display or change the default Useradd configuration
-E,--expiredate expire_date expiration date for new account
-F,--inactive inactive new account password inactivity period
-G, the name or ID of the--gid group's new account owner
-G,--groups groups additional group list for new account
-H,--help displays this help information and launches
-K,--skel Skel_dir Use this directory as the skeleton directory
-K,--key key=value do not use default values in/etc/login.defs
-L,--no-log-init do not add this user to the most recent logon and logon failure database
-M,--create-home create the user's home directory
-M,--no-create-home does not create a user's home directory
-N,--no-user-group does not create a group with the same name
-O,--non-unique allows users to be created with duplicate UID
-p,--password password new account password after encryption
-R,--system create a System account
-R,--root Chroot_dir CHROOT to the directory
-S,--shell Shell login shell for new account
-U,--uid uid user ID of new account
-U,--user-group create a group with the same name as the user
-Z,--selinux-user Seuser uses the specified seuser for SELinux user mappings



13th one


Attention:
1, write timed tasks, to add comments
2, timed task rules if it is a command, and has been redirected or appended, generally do not add >/dev/null 2>&1
3. To use absolute path, absolute path is the full path starting from the root.
4, of course, also to ensure that the path corresponding to the directory exists only, log file Oldboy.log can not.
5, to use >> append, not > coverage.
6. Go to the parent directory of the packaged file or directory to package.
7, the scheduled task is by the hour, packaging in the date to be accurate to the hour.


VI in X is locking Wq save

18th Day-linux System scheduled task Crond in-depth combat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.