本文介绍了shell脚本和cron问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个备份脚本,为本地开发服务器(运行Ubuntu服务器版本9.10),只是一个简单的脚本,焦油和放大器; gzip压缩本地根,并坚持在备份文件夹中。
当我运行正常工作:

I've written a backup script for our local dev server (running Ubuntu server edition 9.10), just a simple script to tar & gzip the local root and stick it in a backup folder.It works fine when I run :

$ bash backups.sh

但是当我通过crontab中运行它不会工作。

but it wont work when I run it through crontab.

59 23 *  *  *  bash /home/vnc/backups/backup.sh >> /home/vnc/backups/backup.log 2> $1

我得到错误信息

/bin/sh: cannot create : nonexistent

这个脚本将tar.gz它是从(/家/ USER1)上运行的文件夹中,但随后尝试将其复制到安装的份额从(/家/备份,这实在是192.168.0.6/backups~~V)网络驱动器,通过使用fstab文件。
安装的份额有权限777,但所有者和组是那些运行脚本不同。
我使用bash运行的脚本,而不是SH来解决另一个问题,我已经在过去以坏替代的错误

The script makes the tar.gz in the folder it is running from (/home/user1), but then tries to copy it to a mounted share (/home/backups, which is really 192.168.0.6/backups) from a network drive, via using fstab.The mounted share has permissions 777 but the owner and group are different to those running the script.I'm using bash to run the script instead of sh to get around another issue I've had in the past with "bad substitution" errors

第2行的文件是

! /bin/bash

cd /home/vnc/backups

我可能没有提供足够的信息来完整地回答这个职位,但是我可以根据需要发布更多的信息,但我真的不知道去哪里看旁边

I'm probably not supplying enough information to fully answer this post yet but I can post more information as necessary, but I don't really know where to look next.

推荐答案

线索是错误消息:

/bin/sh: cannot create : nonexistent

请注意,它说:SH。 Bourne shell的不支持某些功能特定于猛砸。如果你正在使用bash的功能,那么你需要告诉bash运行脚本。

Notice that it says "sh". The Bourne shell doesn't support some features that are specific to Bash. If you're using Bash features, then you need to tell Bash to run the script.

请您文件的第一行:

#!/bin/bash

或在你的crontab条目做到这一点:

or in your crontab entry do this:

* * * * * /bin/bash scriptname

在没有看到你的crontab条目,你的脚本,很难有任何更具体。

Without seeing your crontab entry and your script it's hard to be any more specific.

这篇关于shell脚本和cron问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 16:13