bash脚本在启动时工作,不';终端中的t

bash脚本在启动时工作,不';终端中的t,bash,amazon-ec2,crontab,subshell,Bash,Amazon Ec2,Crontab,Subshell,我正在AmazonEC2中创建一个服务器,并将bash脚本作为userdata传递给它,该脚本在服务器首次启动时运行。它包括一个命令,用于为使用应答的用户向crontab添加一行 directory=“/home/intahwebz/current/tools/amazon/” command=“cd$directory&&sh backupSQLToS3.sh” job=“15 1*/2**$command” cat看起来您正在使用bourne shell(/bin/sh)来执行bash脚本。

我正在AmazonEC2中创建一个服务器,并将bash脚本作为userdata传递给它,该脚本在服务器首次启动时运行。它包括一个命令,用于为使用应答的用户向crontab添加一行

directory=“/home/intahwebz/current/tools/amazon/”
command=“cd$directory&&sh backupSQLToS3.sh”
job=“15 1*/2**$command”

cat看起来您正在使用bourne shell(
/bin/sh
)来执行bash脚本。尝试使用
bash
而不是
sh

您的方法非常适合我:

$ whoami
test

$ echo $SHELL
/bin/bash

$ command="cd $directory && sh backupSQLToS3.sh"

$ job="15 1 */2 * * $command"

$ crontab -l


$ cat <(fgrep -i -v "$command" <(crontab -u test -l)) <(echo "$job") | crontab -u test -

$ crontab -l

15 1 */2 * * cd  && sh backupSQLToS3.sh
$whoami
测试
$echo$SHELL
/bin/bash
$command=“cd$目录和&sh backupSQLToS3.sh”
$job=“15 1*/2**$command”
$crontab-l

$cat听起来您的shell不支持
我将脚本称为'bash installCrontab.sh',它有#/bin/bash位于顶部,因此我非常确定它使用的是bash。谢谢-当我从命令行执行此操作时,它对我很有效,因此我将所有内容复制并粘贴到一个新的脚本文件中,它在那里也很有效。比较这两个脚本显示我在第一个中间得到了额外的空间。
installCrontab.sh: line 14: syntax error near unexpected token `('
installCrontab.sh: line 14: `cat <(fgrep -i -v "$command" <(crontab -u intahwebz -l)) <(echo "$job") | crontab -u intahwebz -'
$ whoami
test

$ echo $SHELL
/bin/bash

$ command="cd $directory && sh backupSQLToS3.sh"

$ job="15 1 */2 * * $command"

$ crontab -l


$ cat <(fgrep -i -v "$command" <(crontab -u test -l)) <(echo "$job") | crontab -u test -

$ crontab -l

15 1 */2 * * cd  && sh backupSQLToS3.sh