I run screen command through cron, where the codes is in lorem.sh files.This is cron codes: * * * * * cd /home/z; ./lorem.shInside lorem.sh:screen -S screenname -X stuff $'\033[B'sleep 1 && screen -S screenname -X stuff 2sleep 1 && screen -S screenname -X stuff lorem ipsum dolorsleep 1 && screen -S screenname -X stuff $'\n'Above lorem.sh codes: First line is Arrow down, and forth line is EnterWhen running lorem.sh through cron, only second & third line working.Above lorem.sh works fine if run from terminal by typing ./lorem.sh but not working from cron
Run screen command with variable & tick through cron (cron run .sh)
cron;gnu screen
Most versions of cron run commands using /bin/sh by default, and if the commands run any shell scripts (that don't have a #! line to force use of a specific shell), /bin/sh will be used to run them, too.On some systems, /bin/sh is dash, a shell that doesn't understand the ANSI-C quoting convention used by bash and other shells. So your $'\n' string is probably getting interpreted as the 3-character string $\n.Most versions of cron will let you specify a shell to run your commands. You can have it use bash by editing your crontab to add a lineSHELL=/bin/bashthat comes before any lines that schedule jobs.Alternatively, you can make lorem.sh always use bash by adding#!/bin/bashas its first line.