Linux的cron与%
The purpose of this document is to explain how to cope with the percentage sign (%) in a crontab entry.
Usually, a % is used to denote a new line in a crontab entry. The first % is special in that it denotes the start of STDIN for the crontab entry's command. A trivial example is:
* * * * * cat - % another minute has passed
This would output the text
another minute has passed
After the first %, all other %s in a crontab entry indicate a new line. So a slightly different trivial example is:
* * * * * cat - % another % minute % has % passed
This would output the text
another
minute
has
passed
Note how the % has been used to indicate a new line.
The problem is how to use a % in a crontab line to as a % and not as a new line. Many manuals will say escape it with a \. This certainly stops its interpretation as a new line but the shell running the cron job can leave the \ in. For example:
* * * * * echo '\% another \% minute \% has \% passed'
would output the text
\% another \% minute \% has \% passed
Clearly, not what was intended.
A solution is to pass the text through sed. The crontab example now becomes:
* * * * * echo '\% another \% minute \% has \% passed'| sed -e 's|\\||g'
This would output the text
% another % minute % has % passed
which is what was intended.
This technique is very useful when using a MySQL command within a crontab. MySQL command can often have a % in them. Some example are:
- SET @monyy=DATE_FORMAT(NOW(),"%M %Y")
- SELECT * FROM table WHERE name LIKE 'fred%'
So, to have a crontab entry to run the MySQL command
mysql -vv -e "SELECT * FROM table WHERE name LIKE Fred%'" member_list
would have to appear in the crontab as
echo "SELECT * FROM table WHERE name LIKE 'Fred\%'" | sed -e 's|\\||g' | mysql -vv member_list
Linux的cron与%的更多相关文章
- 通过Linux系统Cron执行OwnCloud计划任务
通过Linux系统Cron执行OwnCloud计划任务 02/02/2013 CRON的确是一个非常有用的功能,它有效减少了系统的负载,在将WordPress和StatusNet的任务计划都转换到Cr ...
- linux中Cron定时任务系统命令详解
分类:Linux VPS教程 作者:阿川 发布时间:October 13, 2011 有很多同学在购买VPS之后,需要用到计划任务.但是又对计划任务不太了解,所以.今天我们的帮助中心主要是给大家提供一 ...
- Linux 通过cron定期执行 php文件(转)
Linux 通过cron定期执行 php文件 补充几点: 1. 要在php文件头加上解释器的路径,通常是 #!/usr/bin/php 2. 授予要执行的php文件执行权限 chmod a+x x ...
- Linux Schedule Cron All In One
Linux Schedule Cron All In One 定时任务 / 定时器 GitHub Actions Scheduled events Cron syntax has five field ...
- Linux下cron的使用
cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动.关闭这个服务: /sbin/service c ...
- linux的cron服务及应用
Linux下的Cron用于定时执行设置的周期性指令,是Linux的内置服务,可以用以下的方法启动.关闭这个服务: /sbin/service crond start //启动服务 /sbin/serv ...
- linux操作系统cron详解
Linux操作系统定时任务系统 Cron 入门 cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动 ...
- (转载)Linux定时任务cron配置
(转载)http://blog.csdn.net/jbgtwang/article/details/7995801 实现linux定时任务有:cron.anacron.at等,这里主要介绍cron服务 ...
- PHP结合Linux的cron命令实现定时任务
PHP死循环 来处理定时任务的效率是很低的.(众多网友评价)大家都建议使用Linux内置的定时任务crontab命令来调用php脚本来实现. PHP定时任务的两种方法:1.web方式调用php网页,但 ...
- Linux的cron和crontab
一 cron crond位于/etc/rc.d/init.d/crond 或 /etc/init.d 或 /etc/rc.d /rc5.d/S90crond,最总引用/var/lock/subsys/ ...
随机推荐
- [学习笔记]Java作用域变量申明和C、C++的差异性
Java作用域 大多数程序设计语言都提供了“作用域”(Scope)的概念.对于在作用域里定义的名字,作用域同时决定了它的“可见性”以及“存在时间”.在C,C++和Java 里,作用域是由花括号的位置决 ...
- Navicat Premium
Navicat Premium Navicat Premium,一个专门用于操作各种数据库的工具,oracle,sql server,mysql,db2,access等等 下载链接:https://d ...
- windows下sublime通过sftp扩展上传文件到linux服务器上
首先在package controll下载sftp扩展,在任意磁盘下新建文件夹: 然后,添加该文件夹到sublime中,并在xhell中链接linux服务器,新建目录,mkdir /home/hel ...
- 2017-05~06 温故而知新--NodeJs书摘(一)
前言: 毕业到入职腾讯已经差不多一年的时光了,接触了很多项目,也积累了很多实践经验,在处理问题的方式方法上有很大的提升.随着时间的增加,愈加发现基础知识的重要性,很多开发过程中遇到的问题都是由最基础的 ...
- 并行(多进程)-python
1.进程创建 2.当前进程信息 使用current_process可获得当前进程的信息: (1)引入:from multiprocessing import current_process (2)获取 ...
- 20165203 《网络对抗技术》week1 Kali的安装与配置
20165203 <网络对抗技术>week1 Kali的安装与配置 本人感觉Kali可以做很多有意思的事情,下面是本人的Kali的安装过程. 安装过程 光盘映像文件的下载 登录官网,选择下 ...
- Yann Martell《少年 pi 的奇幻漂流》
事情并没有像我们预想的那样发生,你能怎么办呢?无论生活以怎样的方式向你走来,你都应该勇敢地面对它,尽可能地享受它!
- silverlight处理gif格式图片
1.在工具箱中添加dll文件 2.工具栏中将显示此控件,填写xaml文件 <UserControl xmlns="http://schemas.microsoft.com/winfx/ ...
- 为什么Nginx性能比Apache高
Nginx的工作原理 nginx在启动后,会有一个master进程和多个worker进程.master进程主要用来管理worker进程,包含:接收来自外界的信号,向各worker进程发送信号,监控wo ...
- 交叉编译和安装ARM板(RK3288)和Linux 3.10上的RTL8188无线网卡驱动
插入无线网卡,输入ifconfig,发现没有检测到网卡. 输入lsusb,查看无线网卡型号. 我用的无线网卡是EDUP的网卡,包装盒里有一张驱动光盘,把光盘里linux下的驱动目录复制下来.如果没有驱 ...