Ubuntu รองรับ“ @reboot” ใน crontab หรือไม่


23

Ubuntu รองรับ@rebootcrontab หรือไม่

ฉันพบเอกสารที่แนะนำว่ารองรับ แต่การแช็ทผ่านเว็บไม่สามารถทำได้

ฉันไม่สามารถทำให้@rebootส่วนทำงานได้ ส่วน "หลังเที่ยงคืน" ใช้งานได้ดี

นี่คือตัวอย่างทดสอบจากฉัน/etc/crontab:

$ cat /etc/crontab
# /etc/crontab: system-wide crontab

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
##

# in the beginning - 
@reboot /var/kiosk/btest.sh

# after midnight
30 0     * * *   root    /etc/cron.daily/kiosk/kioskReboot.sh

# end of crontab

เชลล์สคริปต์ btest.sh

#!/bin/bash
date > /var/kiosk/STARTFLAG.txt
echo we booted >> /var/kiosk/STARTFLAG.txt
date
echo we booted

สิทธิ์

$ ls -l btest.sh
-rwxrwxrwx 1 root root 147 Aug 21 15:19 btest.sh
$ ls -ld
drwxrwxrwx 14 laptopsanytime root 4096 Aug 21 16:30 .


คุณคิดเกี่ยวกับการสร้างสคริปต์ btest.sh, autostart askubuntu.com/a/9388/2973
wojox

มีคำตอบที่ยอดเยี่ยมเกี่ยวกับ Unix & Linux ' [crontab's @reboot ใช้สำหรับ root เท่านั้น]] [1] [1]: unix.stackexchange.com/q/109804/17362
Édouard Lopez

ฉันมีใน crontab ส่วนตัวของฉัน @reboot กฎที่ใช้งานได้โอเคลักษณะเช่นนี้:@reboot sh /home/me/run-stuff.sh
taneli

ในกรณีที่ไม่มีใครได้รับมันเขากำลังผสม crontabs: / etc / crontab เป็นผู้ใช้ crontab และต้องการผู้ใช้ crontab -e เป็น crontab ส่วนบุคคลและใช้ผู้ใช้ที่มีการใช้งานในขณะที่แก้ไขดังนั้นไม่จำเป็นต้องมีชื่อผู้ใช้ ทั้งสองยอมรับ @reboot
Rinzwind

คำตอบ:


21

@reboot ได้รับการสนับสนุนใน Ubuntu เหตุผลที่เข้าร่วมของคุณ

@reboot /var/kiosk/btest.sh

ไม่ทำงานใน / etc / crontab เพราะไม่มีฟิลด์ผู้ใช้ ไวยากรณ์ที่ถูกต้องจะเป็น

@reboot root /var/kiosk/btest.sh

2
อย่างน้อยใน 14.04 นี่ไม่ใช่กรณีและผิด "man 5 crontab" ไม่ได้พูดถึงเช่นกัน อาจจะขึ้นอยู่กับรุ่น แต่ฉันสงสัยมัน
vorburger

1
@vorburger ถ้าคุณหมายถึง@rebootไม่ได้รับการสนับสนุนนี่คือลิงค์ไปยัง wikiที่ระบุว่าทำ BTW ในวันที่ 14.04 ของฉันman 5 crontabบอกเกี่ยวกับ@reboot
Fr0zenFyr

4
ใน Ubuntu 14.04 ของฉันเพื่อให้ผู้ใช้บางคนsomeuserเรียกใช้คำสั่งในการบูตโดยอัตโนมัติฉันต้องเพิ่มรายการ crontab ของผู้ใช้นั้นโดยไม่ต้องระบุชื่อผู้ใช้:@reboot /var/kiosk/btest.sh
Abdull

1
เพิ่มในการสนทนาฉันใช้ Ubuntu 16.4.05 เมื่อใช้ผู้ใช้ crontab คำสั่ง @reboot จะทำงานโดยไม่ระบุผู้ใช้ที่จะเรียกใช้เป็นและไม่ทำงานเมื่อระบุผู้ใช้
Keith Reynolds

1

Ubuntu 16.04.5 LTS: ตามรูท:

crontab -e

เพิ่มบรรทัดต่อไปนี้:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@reboot /path_to_script.sh 2>&1 >> /path_to_log.log

2> & 1 >> จะส่งเอาต์พุต stdout ไปที่ /path_to_log.log เพื่อให้คุณสามารถแก้ไขปัญหานี้ได้


0

มันทำงานบน 18.04 cron.dเป็นงานที่กำหนดไว้ใน
ฉันป้อนสิ่งนี้ในไฟล์งาน:

PATH = / usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin
@reboot root /path/to/script.sh


1
การเพิ่มรูทไม่ได้ผลสำหรับฉัน คุณใช้ crontab -e เป็น root หรือไม่
MKZ

ฉันบันทึกไปยังไฟล์ start_at_reboot ในไดเรกทอรี /etc/cron.d
TheR
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.