I am writing a bash script that is suppose to auto restart my autofs in a loop. but when I try to run it I just get a syntax error.
#./dd_nfs.sh
./dd_nfs.sh: line 3: syntax error near unexpected token `/etc/init.d/autofs'
./dd_nfs.sh: line 3: `/etc/init.d/autofs reload'
# cat dd_nfs.sh
#!/bin/bash
for i in `seq 1 10`
/etc/init.d/autofs reload
sleep 5
echo "read test"
do time echo "read"
echo "read test done"
done
I tried the dos2unix. I replaced line 3 with just 'pwd' to print my current dir and I tried to strip out the /r but I still get the same error. So I am not sure what's going here.
Has anyone seen this before? Thanks
for ... do ... done. You missed thedodoafter the for loop definition, before theautofs reloadlinedohas to be immediately after thefor; you can't just add it on some arbitrary line. The line you added in the edit will just cause another syntax error. Consult the bash documentation for the syntax of aforloop.catcommand. That matters; the#!must be at the very beginning of the line. Please include an actual copy-and-pasted script in your question, one that reproduces the problem. If your original script is too big, reduce it to something smaller, verify that the problem occurs with the smaller script, and copy-and-paste that into your question. By editing your script without checking it, you've been introducing new errors.