Home>

Create a shell script that adds information to the text file,
I made it run every minute with cron.
When I checked the log, it seems that cron is running, but it is not added to the text file.
Are there any other settings? Please give me a solution.

Contents of shell script

#!/bin/bash
str1 = $(date "+% Y% m% d% H% S")
str2 = $(cat/dev/urandom | tr -dc "[: alpha:]" | fold -w 10 | head -n 1)
str3 = $((RANDOM% + 10000))
cat<<EOF >>test.text
$str1 $str2 $str3
EOF

cron settings
*/5 * * * * /home/sakura/cobol_test/test.sh

Result of crontab -l
*/5 * * * * /home/sakura/cobol_test/test.sh

Contents of var/log/cron
Oct 25 10:30:01 tk2-260-39672 CROND [27118]: (sakura) CMD (/home/sakura/cobol_test/test.sh)
Oct 25 10:31:01 tk2-260-39672 CROND [27163]: (sakura) CMD (/home/sakura/cobol_test/test.sh)
Oct 25 10:32:02 tk2-260-39672 CROND [27202]: (sakura) CMD (/home/sakura/cobol_test/test.sh)

  • Answer # 1

    Thank you very much.
    As pointed out by dodox86
    There was test.text under the home directory/home/sakura /, and it was added to that file.
    There was insufficient confirmation.
    I'm sorry.

  • Answer # 2

    I can't say anything because the code for the Shell script isn't provided,
    It's okay when I run Shell at the prompt, but when cron doesn't work as expected
    There are many differences in environment variables depending on whether or not you are logged in. (Mostly the command cannot be executed because the path does not pass)

  • Answer # 3

    When a shell script that works independently does not work well when started from cron, it is often related to PATH.
    If you rewrite all the commands used in the shell script to the full path, it usually works, but that is also difficult, and it is not good if you are referring to environment variables other than PATH.

    If you search around "crontab environment variable", you will find some ways to do it, so please refer to it.