when i run sh backuptest.sh, following error comes .So is it issue with the code or my shell
result :
: not foundsh: 2: backuptest.sh:
: not foundsh: 4: backuptest.sh:
: not foundsh: 6: backuptest.sh:
: not foundsh: 7: backuptest.sh:
content of backuptest.sh
#!/bin/sh -e
location=`date +%Y%m%d`.sql
mysqldump -u root -proot spider_db > $location
remove #!/bin/sh -e and try
dos2unix backuptest.sh
then execute again with
./backuptest.sh
Related
a=HDH b=udud c=jsjsj bash secondscript
The command above works. I'd like to save the assignments in a variable, like so:
value="\
a=HDH \
b=udud \
c=ududj \
"
$value bash secondscript
But it gives an error:
test.sh: line 9: a=HDH: command not found
Why? What can I do instead?
bash's taking first item a=HDH as a command, what you need is :
value=(
"a=HDH"
"b=udud"
"c=ududj"
)
env "${value[#]}" bash secondscript
Have an error "Syntax error: "(" unexpected" when execute an script:
sync.sh: 11: sync.sh: Syntax error: "(" unexpected
line 11 contains on this:
declare -a FOLDERS=('/scripts' '/backup')
and on the top of script have the interpreter:
#!/bin/bash
Execute the script with:
sh /wdmycloudex2/$(hostname)/scripts/sync.sh
/wdmycloudex2/RASPBIAN/scripts/sync.sh: 11: /wdmycloudex2/RASPBIAN/scripts/sync.sh: Syntax error: "(" unexpected
The firsts 11 lines:
#!/bin/bash
IP='10.0.1.7'
PORT='443'
HOSTNAME=$(hostname)
DATE=$(date +%d%m%Y_%H%M%S)
SOURCE='/scripts'
DEST='/wdmycloudex2'
declare -a FOLDERS=('/scripts' '/backup')
anybody know and explain what's the problem?
The header #!/bin/bash is ignored when you start the script with sh sync.sh.
It will go better with bash /wdmycloudex2/RASPBIAN/scripts/sync.sh or
chmod +x /wdmycloudex2/RASPBIAN/scripts/sync.sh
/wdmycloudex2/RASPBIAN/scripts/sync.sh
Trying to execute SED against a file from chef is yielding an error, that I am having trouble tracking down
It runs without issue from the console:
sed -i.bak -e "\$aolcRootPW: {SSHA}Z/+CHVP/Vx3bA2m6l0aI6uvIMhJUitpT" /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif
However from my recipe:
bash 'UPDATE /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif #3' do
code <<-EOH
sed -i.bak -e "\$aolcRootPW: {SSHA}Z/+CHVP/Vx3bA2m6l0aI6uvIMhJUitpT" /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif
EOH
end
I am getting the following error
================================================================================
Error executing action `run` on resource 'bash[UPDATE /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif #3]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "bash" "/tmp/chef-script20151029-7070-y3iz58" ----
STDOUT:
STDERR: sed: -e expression #1, char 8: unexpected `}'
---- End output of "bash" "/tmp/chef-script20151029-7070-y3iz58" ----
Ran "bash" "/tmp/chef-script20151029-7070-y3iz58" returned 1
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/3rd-open-ldap-server/recipes/default.rb
64: bash 'UPDATE /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif #3' do
65: code <<-EOH
66: sed -i.bak -e "\$aolcRootPW: {SSHA}Z/+CHVP/Vx3bA2m6l0aI6uvIMhJUitpT" /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif
67: EOH
68: end
69: bash 'UPDATE /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif #4' do
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/3rd-open-ldap-server/recipes/default.rb:64:in `from_file'
bash("UPDATE /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif #3") do
action [:run]
retries 0
retry_delay 2
default_guard_interpreter :default
command "UPDATE /etc/openldap/slapd.d/cn\\=config/olcDatabase\\=\\{2\\}bdb.ldif #3"
backup 5
returns 0
code " sed -i.bak -e \"$aolcRootPW: {SSHA}Z/+CHVP/Vx3bA2m6l0aI6uvIMhJUitpT\" /etc/openldap/slapd.d/cn=config/olcDatabase={2}bdb.ldif\n"
interpreter "bash"
declared_type :bash
cookbook_name "3rd-open-ldap-server"
recipe_name "default"
end
Confusingly I don't know what character 8 is. I suspect that it is some sort of escaping issue - but I have no idea where.
Update (to provide insight to where it is not): I think it is in the sed command and not the file name as this command works without issue from chef:
bash 'UPDATE /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif #2' do
code <<-EOH
sudo sed -i.bak s/dc=my-domain,dc=com/dc=my,dc=lan/g /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif
EOH
end
I suspect the problem is that there is some environment being set up when you wrap the command where the $a... is getting some bogus shell var substitution done on it. What if you just use single quotes and ditch the \ to try to prevent any such thing?
I.e.:
bash 'UPDATE /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif #3' do
code <<-EOH
sed -i.bak -e '$aolcRootPW: {SSHA}Z/+CHVP/Vx3bA2m6l0aI6uvIMhJUitpT' /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif
EOH
end
I needed to double escape the $ at the start of the sed expression:
bash 'UPDATE /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif #3' do
code <<-EOH
sed -i.bak -e "\\$aolcRootPW: {SSHA}Z/+CHVP/Vx3bA2m6l0aI6uvIMhJUitpT" /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif
EOH
end
We have application. As part of application - we have set of bash-scripts.
Sctips now are in tar-archive:
$ ls -l manager/
total 3076
-rwx------+ 1 Administrators Domain Users 3123200 Jan 8 15:47 manager.tar
Then, after TeamCity build, Maven creates jar-file like "manager.jar" which includes "manager.tar" inside.
After unpack jar and then tar - all works.
But!
If put bash-scripts without pack them in to tar-archive - after build and unpack jar-file - I always got very odd error:
$ ./manager.sh -h
: No such file or directory
$ bash -x manager.sh
+ $'\r'
: command not foundne 2:
+ $'\r'
: command not foundne 10:
'anager.sh: line 11: syntax error near unexpected token `{
'anager.sh: line 11: `setbase () {
Although - both manager.sh scripts (from both builds) looks same (diff && vimdiff).
UPD
When removing all 'newlines' in script - it seems to be work, little example:
setbase () { if [ "$1" = "SIT" ]; then
and then execution with -xv:
setbase () { if [ "$1" = "SIT" ]; then
export BASEDIR="/home/user/APP"
export smem="32G"
export xmem="32G"
elif [ "$1" = "DEV" ]; then
manager/manager.sh: line 13: syntax error near unexpected token `elif'
'manager/manager.sh: line 13: `elif [ "$1" = "DEV" ]; then
But VIM doesn't show any symbols like ^M, also - both file in same encoding:
(this one work)
$ file -ib /home/user/APP/manager/manager.sh
text/x-java charset=us-ascii
(this one - no)
$ file -ib manager/manager.sh
text/x-java charset=us-ascii
The problem is DOS line endings. This might be related to the jar packing or your new scripts might just be the only DOS line ending files you have. In either case fix that.
I get a Delimter Error in a Shell Script:
#!/bin/sh
result=`psql -d databasename -t -A <<EOF
SELECT COUNT(*) FROM schema.table
WHERE "column_name_x" = 'specific_value_x'
AND "column_name_y" = 'specific_value_y'
AND ("column_name_z" LIKE 'specific_z%' OR "column_name_za" LIKE 'specific_za%')
;`
EOF
echo $result
#EOF
The result of the Script is fine. But I get two warnings:
./filename.sh: line 13: warning: here-document at line 8 delimited by end-of-file (wanted `EOF')
./filename.sh: line 9: EOF: command not found
What is the problems here? Thank you!
You have the start of your here-doc inside of your command, but the EOF is outside of your command.
result=`psql -d databasename -t -A <<EOF
SELECT COUNT(*) FROM schema.table
WHERE "column_name_x" = 'specific_value_x'
AND "column_name_y" = 'specific_value_y'
AND ("column_name_z" LIKE 'specific_z%' OR "column_name_za" LIKE 'specific_za%')
EOF
`
The ; seems wrong here too (at least it threw an error for me).