Bash-Skript,Linux cron-Job zu erstellen Datei mit Python
#! /bin/bash
echo 'hi bash'
aa
python ~/fledgling/cron/test.py
echo 'after python script'
hier aa
alias ist, die
alias aa='cd /home/fledgling/projects/myblog/base'
Python-Skript,
import time
with open('~/fledgling/cron/%s.txt' % time.strftime("%Y_%m_%d__%H:%M:%S"), 'w') as f:
f.write('%s' % time.strftime("%Y_%m_%d__%H:%M:%S"))
Ich möchte virtualenv aktiviert, um zu Führen Sie dieses Python-Skript für jede Minute aus.
crontab,
* * * * * ~/fledgling/cron/test.sh >> ~/fledgling/cron/log.txt
Inhalt von ~/junge/cron/log.txt,
hi bash
after python script
Ausgabe von/var/log/syslog
✘ ✝ ~/fledgling/cron tail -f /var/log/syslog
Jun 24 13:46:01 mysys CRON[14697]: (mysys) CMD (~/fledgling/cron/test.sh >> ~/fledgling/cron/log.txt)
Jun 24 13:46:01 mysys CRON[14696]: (CRON) info (No MTA installed, discarding output)
Jun 24 13:47:01 mysys CRON[14736]: (mysys) CMD (~/fledgling/cron/test.sh >> ~/fledgling/cron/log.txt)
Jun 24 13:47:01 mysys CRON[14735]: (CRON) info (No MTA installed, discarding output)
Jun 24 13:48:01 mysys CRON[14747]: (mysys) CMD (~/fledgling/cron/test.sh >> ~/fledgling/cron/log.txt)
Jun 24 13:48:01 mysys CRON[14746]: (CRON) info (No MTA installed, discarding output)
Jun 24 13:48:11 mysys crontab[14769]: (mysys) BEGIN EDIT (mysys)
Jun 24 13:48:59 mysys crontab[14769]: (mysys) END EDIT (mysys)
Jun 24 13:49:01 mysys CRON[14794]: (mysys) CMD (~/fledgling/cron/test.sh >> ~/fledgling/cron/log.txt)
Jun 24 13:49:01 mysys CRON[14793]: (CRON) info (No MTA installed, discarding output)
Berechtigungen,
-rw-rw-r-- 1 mysys mysys 476 Jun 24 13:57 log.txt
-rwxrw-r-- 1 mysys mysys 153 Jun 24 13:37 test.py
-rwxrwxr-x 1 mysys mysys 91 Jun 24 13:32 test.sh
Was ich will? Ich möchte jede Minute eine Textdatei erstellen.
Was ist mein Problem? Ich kann im Protokoll sehen, dass nach jeder Minute läuft Bash-Skript ohne Fehler, warum Python-Skript nicht ausgeführt wird oder keine Textdatei erstellen?
'#!/bin/bash' sollte kein Leerzeichen sein. '~' Wo glaubst du das? – 123