I try to execute an PSQL from shell, and the thing is - it returns the error "command not found". I have a shell script in which there're lines:
ID3=`more DATA/Id3.txt`
psql -h localhost test test -Atc "SELECT id, reference, timestamp FROM restricted WHERE id='`$ID3`'"
In the Id3.txt there's only the ID. When the psql command is written and executed direct through prompt - there's no problem at all and correct value is returned. When executed with a .sh file - error "command not found" is brought up. I have no clue why. Maybe anyone have a idea?
In your script try to add which psql to see whether you can find the executable
Run below command on your console: whereis psql
And then replace psql inyour script with the output of above command. This
Related
I'm having the following issue. When I execute this command sfdx profile:field:add -n "Account.Test" -m re -p "Test" from a Bash script, it's all fine.
However, when I try to execute the following:
sfdx profile:field:add -n "Account.Test" -m re -p "Test Test"
I get this error: 'C:\Program' is not recognized as an internal or external command
When I run the same command in the terminal, it works fine. It's just when I put it inside a bash script that this error happens.
Currently running this on Windows 10.
I'm 100% sure it's the space in that last parameter, I am just not sure how to get around it. Can anyone help?
I've found sh-script for CPU Throttling and would like to schedule it on startup using AppleScript in the following way:
do shell script "sudo /Users/BohdanAir/Documents/Automation/cputhrottler.sh" "password mypassword" with administrator privileges
And get the following error:
error "sudo: /Users/BohdanAir/Documents/Automation/cputhrottler.sh: command not found" number 1
P.S: The pass provided to the sh file is being fully copied from the Get Info option (CDM + I)
Not even sure how you received that error message when the do shell script command shown in your question does not even compile.
The "password mypassword" portion actually has to be password "mypassword" for it to compile.
The reason you're getting:
error "sudo: /Users/BohdanAir/Documents/Automation/cputhrottler.sh: command not found" number 1
Is because cputhrottler.sh is not set as executable.
Make it executable using the following command:
chmod u+x /Users/BohdanAir/Documents/Automation/cputhrottler.sh
This will allow it to execute and not throw that particular error message.
Or use the following convention:
do shell script "sh /Users/BohdanAir/Documents/Automation/cputhrottler.sh" password "mypassword" with administrator privileges
Note that sudo was replaced with sh, or use other shell. In this manner the shell script does not need to be made executable.
I have a shell script with a psql command to update a Redshift table. It's worked several times in the original spot in the shell script, but when I copied the command into another line in the script, I got an error saying psql: command not found.
Here's some pseudocode of where the psql command has and has not worked:
#start
if [ -f filename.txt ];
then echo 'first area';
psql #has not worked here
else psql ; #has successfully worked here
fi;
psql # has not worked here
#end
I'd just like pointers or suggestions to figure out the behavior of this. Is there any plausible explanation for this to work only in that else statement?
I'm using SNMPD to run a script on a Raspberry Pi with net-snmp.
I was able to get the same script running on my Slackware machine, but on the Pi, under extOutput.1, I'm getting "Exec format error".
The batch file being called is set to 777 and is:
#! /bin/bash
/sbin/reboot
Everything I've found about the error says that I would just need to include the #! at the beginning of the file and that would fix it, but it doesn't. I can run the script from the command prompt just fine, and /bin/bash obviously works also, but when called through SNMP (both snmpget and snmpwalk), the extOutput.1 line gives me that error.
Ugh. I had a blank line at the top of the script before the #! line.
I have to take a data dump from my postgres database.
How do I log in to the postgres home ? . I have the following script but it doesn't work :
#!/bin/sh$
export PASSWORD= something
echo $PASSWORD | sudo -S su postgres
pg_dump somedb > dump.txt+`date +%Y-%m-%d`
However when I run this script I do not get logged to postgres#gauss:$ at the same time script doesn't throw an error. Is there something I am doing wrong here ?
The reason your script fails is that the line
echo $PASSWORD | sudo -S su postgres
causes su to fork a subordinate shell. That shell tries to read from the standard input which has already been exhausted by sudo -S in reading the password. When the shell finds no more input (EOF) it exits. The next line of your script then executes as if that quoted line never happened, and therefore runs under your UID.
See j.hloetzek's answer for a much better way to do what you want.
Also the script as pasted has a two syntax errors in it, but you shouldn't use that approach anyway.
You cannot pipe the password to the sudo command, but can allow in /etc/sudoers certain commands to be run without password (check exact syntax!)
username YOURUSERNAME = NOPASSWD: /sbin/su postgres