【问题标题】:how to run a bash script in background automatically?如何在后台自动运行 bash 脚本?
【发布时间】:2016-04-01 14:00:10
【问题描述】:

我需要编写一个自动删除临时文件并每天在后台运行的 bash 脚本。

#!/bin/bash  
while true;  
do      
    rm  /home/c/temp/*
    sleep 24h
done

但它不起作用

【问题讨论】:

标签: linux bash shell unix rm


【解决方案1】:

写一个shell脚本

rm /home/c/temp/*

并在 crontab 中添加一行

crontab -e

添加行

0 12 * * * path/to/script

它会在每天中午执行你的脚本。

【讨论】:

  • 您可能会建议删除 temp 周围不必要的单引号,但这只是样式问题...
  • 是的,只需复制粘贴该行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 2015-05-11
  • 2018-01-23
相关资源
最近更新 更多