linux - 如何在后台自动运行bash脚本?

标签 linux bash shell unix rm

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

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

但是不起作用

最佳答案

编写shell脚本

rm /home/c/temp/*

并在 crontab 中添加一行

crontab -e

添加行

0 12 * * * path/to/script

它将在每天中午执行您的脚本。

关于linux - 如何在后台自动运行bash脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36358300/

相关文章:

python - 为什么 Popen.terminate() 在 Windows 上终止使用命令解释器 (cmd.exe) 运行的子进程?

linux - 直到循环不适用于 shell 中的字符串比较

linux - bash 循环文件回显到目录中的每个文件

node.js - 乌类图 : NPM EACCES error though I changed folder ownership

linux - 从链接的 docker 重命名环境变量

php - Linux Composer安装错误 'The openssl extension is required'

Bash 查找将多个文件替换为新文件

Bash:如何使用包含方括号或其他特殊字符的键来保留和恢复关联数组

string - 为什么 SED 回显而不是编辑 : sed '/^;text1/!b;:a;n;//ba;i\text2'

c - 使用 libelf 提示生成 ELF