我的macbook中有一个cronjob(每10分钟截取一次屏幕截图)和mac osx El Capitan,它遵循以下命令:
*/10 * * * * cd /Users/userx/Pictures/memes && ./shared.sh
shared.sh脚本包含以下内容:
#!/bin/bash
_now=$(date +"%m_%d_%Y_%H_%M_%S")
screencapture -x $_now.png
但是当系统执行cronjob时,我收到了这个错误:
./shared.sh: line 3: screencapture: command not found
但如果我直接在终端中运行shared.sh文件,则所有操作都正确执行。
任何想法?我们可以从cronjobs运行mac osx命令吗?
答案 0 :(得分:2)
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception{
File file = new File("Customers.txt");
Scanner input = new Scanner(file);
Customer[] airlinecustomer;
airlinecustomer = new Customer[40];
Seat[] seats = new Seat[40];
for(int i = 0;i < 40;i++) seats[i] = new Seat();
seatssold = seatssold + input.nextInt();
for(int i = 0;i < seatssold;i++) {
airlinecustomer[i].firstname = input.next();
airlinecustomer[i].lastname = input.next();
airlinecustomer[i].DOB = input.next();
airlinecustomer[i].email = input.next();
airlinecustomer[i].address = input.next();
airlinecustomer[i].telephone = input.next();
airlinecustomer[i].seat = input.nextInt();
seats[i].customer = i;
seats[i].available = "S";
}
//for(int i = 0;i < 40;i++) if(seats[i].available != "S") seats[i].available = "U";
}
public class Customer {
private String firstname;
private String lastname;
private String DOB;
private String email;
private String address;
private String telephone;
private int seat;
public Customer(String firstname,String lastname,String DOB,String email,String address,String telephone,int seat) {
this.firstname = firstname;
this.lastname = lastname;
this.DOB = DOB;
this.email = email;
this.address = address;
this.telephone = telephone;
this.seat = seat;
}
}
public static class Seat {
static String available;
static int customer;
public Seat(String available,int customer) {
this.available = available;
this.customer = customer;
}
}
位于/ usr / sbin中,但cron作业的默认PATH仅为screencapture
,因此找不到它。有几种方法可以解决这个问题:
/usr/bin:/bin
)。/usr/sbin/screencapture -x $_now.png
(即screencapture
)之前在脚本中设置PATH。