简体   繁体   English

如何从Mac执行此Cron作业?

[英]How do i execute this cron job from a mac?

I have a bash script that I can execute with cd ~/Documents/Code/shhh/ && ./testy if i'm in any directory on my computer and that successfully pushes to github which is what i want. 我有一个bash脚本,如果我在计算机上的任何目录中,都可以用cd ~/Documents/Code/shhh/ && ./testy执行,并且可以成功推送到我想要的github。

I'm trying to schedule a cron job to do this daily so I ran crontab -e which opens a nano editor and then I put 30 20 * * * cd ~/Documents/Code/shhh/ && ./testy to run daily at 10:30pm and hit control O, enter and control X. But still it it didn't execute. 我试图安排一个cron作业来每天执行此操作,所以我运行了crontab -e ,它将打开一个nano编辑器,然后我将30 20 * * * cd ~/Documents/Code/shhh/ && ./testy每天运行在10:30 pm并按下控件O,输入并控制X。但是仍然没有执行。 When I type crontab -l it shows my command & I have a You have new mail. 当我键入crontab -l它显示我的命令&我有一个“ You have new mail. message when I open a new window. 打开新窗口时出现提示信息。 Still my command doesn't execute even though it will when I run it from any other directory. 即使从其他任何目录运行该命令,我的命令也不会执行。

I think my crontab job is at /var/at/tmp so I ran 30 20 * * * cd ../../../Users/squirrel/Documents/Code/shhh/ && ./testy but still nothing, even though it does work when I write it out myself from that directory. 我认为我的crontab工作在/var/at/tmp所以我跑了30 20 * * * cd ../../../Users/squirrel/Documents/Code/shhh/ && ./testy但还是一无所有但是当我从该目录中自己写出来时它确实起作用。 Sidenote, I can't enter into the tmp folder even after using sudo 旁注,即使使用sudo后,我也无法进入tmp文件夹

OK When I type in mail I see a lot message and inside i get this error 确定,当我键入mail我看到很多消息,并且在内部出现此错误

---------------Checking Status of 2--------------- [master 0c1fff8] hardyharhar 1 file changed, 1 insertion(+), 1 deletion(-) fatal: could not read Username for 'https://github.com': Device not configured

When you by default open nano Input_file it opens it up in INSERT mode(unlike vi where we have to explicitly go to INSERT mode by pressing i key). 默认情况下,当您打开nano Input_file ,它将以INSERT模式打开(不同于vi ,我们必须通过按i键显式进入INSERT模式)。 Now when you have done CTNRL+O it will then ask you if you want to save changes to opened file or not eg--> File Name to Write: Input_file If you press ENTER then it will save it and will be back on the screen(to your Input_file) where you entered new line. 现在,当您完成CTNRL+O ,它将询问您是否要将更改保存到打开的文件中,例如-> File Name to Write: Input_file如果按ENTER,则它将保存并返回到屏幕上(到您的Input_file)在其中输入新行的位置。 Now you could press CONTRL+X to come out of Input_file. 现在,您可以按CONTRL+X键退出Input_file。 May be you are stuck after saving it and want to come out then try this out once? 保存后可能会卡住并想出来然后再尝试一次?

crontab -e does not edit the crontab file "live" at all -- changes are saved to the active file only after you save changes and exit the editor. crontab -e根本不编辑crontab文件“实时”-仅在保存更改退出编辑器后,更改才会保存到活动文件中。

It also sounds like you may be using incorrect directory paths. 听起来您使用的目录路径也不正确。 The command in a crontab entry will generally be executed starting from the user's home directory. 通常,将从用户的主目录开始执行crontab条目中的命令。 So if your home directory is /Users/squirrl, the command cd ../parent_directory/ will try to move to /Users/parent_directory. 因此,如果您的主目录是/ Users / squirrl,则命令cd ../parent_directory/将尝试移至/ Users / parent_directory。 I suspect this is not what you want. 我怀疑这不是您想要的。

Finally, note that cron jobs run with a very minimal environment, without running most of your usual shell setup files (eg .bashrc). 最后,请注意,cron作业在非常小的环境下运行,而没有运行大多数常用的shell安装文件(例如.bashrc)。 Most notably, if your script uses any commands that aren't in /bin or /usr/bin, you'll either need to use explicit full paths to them, or change the PATH variable to include the directories they're in. 最值得注意的是,如果脚本使用/ bin或/ usr / bin中没有的任何命令,则您将需要使用它们的显式完整路径,或者更改PATH变量以包含它们所在的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM