Answer the question
In order to leave comments, you need to log in
How to fix shell script?
I'm trying to create a log with the current date and run a python script in this log
, I can't figure out if I'm calling the _file variable correctly?
#!/bin/sh
_now=$(date +"%d-%m-%Y-%H-%m")
_file="/home/folder/logs/log_$_now.txt"
sudo touch $_file
cd /home/folder/logs
sudo python3 handleMouseEvent.py > ${_file}
Answer the question
In order to leave comments, you need to log in
$ ls -ld /home/folder/logs
will most likely return something like:
give write permissions to the folder to all users:
and throw out sudo from the script:
#!/bin/sh
NOW=$(date +"%d-%m-%Y-%H-%m")
PYFILE="/home/folder/logs/handleMouseEvent.py"
LOGFILE="/home/folder/logs/log_$NOW.txt"
python3 $PYFILE > $LOGFILE
Why do you need sudo to create a file and run python?
If you need sudo - run the whole script, that is:
#!/bin/sh
OUTFILE="/home/folder/logs/log_$(date +"%d-%m-%Y-%H-%m").txt"
cd /home/folder/logs
python3 handleMouseEvent.py > ${OUTFILE}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question