I have a bash script as such:
GITUSER="mygituser"
DBUSER="mysitedbuser"
DB="mysitedb"
SITE="mysite.com"
REPO="/var/git/myproject.git" # on the server
dropdb -U $DBUSER $DB &&
echo "remote db dump (gzip)" &&
F=`ssh $GITUSER#$SITE $REPO/dumpdb-gzip.sh` &&
echo "copying remote dump to localhost" &&
scp $GITUSER#$SITE:"$F" . &&
echo "deleting remote file" &&
ssh $GITUSER#$SITE rm "$F" &&
echo "loading dump in local db" &&
createdb -U $DBUSER -E UTF8 -O $DBUSER $DB &&
psql -U postgres -c "ALTER SCHEMA public OWNER TO $DBUSER" $DB &&
F=`echo "$F" | sed 's/^\/tmp\///'` &&
zcat "$F" | psql -q -f - -U $DBUSER $DB >/dev/null &&
rm "$F"
But running in on Mac OS X (Lion) gives me this error:
$ ./fetch_server_db.sh
remote db dump (gzip)
copying remote dump to localhost
pg_dump_2011-10-25_09-20-50.db.gz 100% 1017KB 254.2KB/s 00:04
deleting remote file
loading dump in local db
ALTER SCHEMA
./fetch_server_db.sh: line 24: 25878 Broken pipe: 13 zcat "$F"
25879 Segmentation fault: 11 | psql -q -f - -U $DBUSER $DB > /dev/null
I do not have such an error on Snow Leopard and this script continues to work perfectly fine on my arch linux machine. This script is failing with segmentation fault only after I upgraded to Lion.
Any idea what could be the problem? If no immediate answer is obvious, pointing me in the right direction to debug this script or to locate the source of the problem on Mac OS X Lion will do just fine! :-)
UPDATE
I have further isolated this problem to possibly blame it on postgresql 9.0.5. Specifically, when the line:
zcat "$F" | psql -q -f - -U $DBUSER $DB >/dev/null
is being executed (I ran the commands manually one by one in terminal), I get a "Segmentation fault: 11" error from postgresql, like this:
zcat "$F" | psql -q -f - -U mysitedbuser mysitedb >/dev/null
psql:-:32: ERROR: relation "acl_dummy" already exists
psql:-:46: ERROR: relation "acl_dummy_id_seq" already exists
Segmentation fault: 11
And this is the psql version I am using on my Lion:
$ psql --version
psql (PostgreSQL) 9.0.5
contains support for command-line editing
$ which psql
/opt/local/lib/postgresql90/bin/psql
$ psql -U postgres
psql (9.0.5)
Type "help" for help.
postgres=#
Any suggestions what else I can do?
The problem occurs for Xcode 4.2 compiled postgresql packages (screws up both postgresql90 and postgresql91). (see https://trac.macports.org/ticket/30090)
The solution is to write your own Portfile in ~/ports/databases/postgresql90/Portfile by appending somewhere to line 9:
revision: 1
and appending somewhere to line 40:
if {${configure.compiler} == "clang"} {
configure.compiler llvm-gcc-4.2
}
Then, copy over the entire "files" subdirectory from /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/databases/postgresql90/files
Make sure that in /opt/local/etc/macports/sources.conf, add in
file:///Users/whateveryourusernameis/ports
before the url pointing to
rsync://rsync.macports.org/release/tarballs/ports.tar [default]
Then do a portindex in ~/ports or do a sudo port -v selfupdate.
And finally uninstall the previous clang compiled postgresql90 package, clean it:
sudo port -v uninstall postgresql90 postgresql90-server
sudo port clean postgresql90 postgresql90-server
and then reinstall with:
sudo port -v install postgresql90 postgresql90-server
During this reinstallation step, you should notice in the stdout that your postgresql90 packages are now being compiled by llvm-gcc-4.2.
As a general note for compilation of packages via MacPorts, we can choose which compiler to use for a specific package (port) by using the recommendations here - https://trac.macports.org/wiki/PortfileRecipes#compiler
Actually, postgres90#9.0.6 already include this amendment.
You can upgrade just by executing:
sudo port -v uninstall postgresql90
sudo port -v install postgresql90
The same happens with postgresql91
Related
I need to use a bash script:
Launch the container
Generate a password
Enter the container
Run the 'cd /' command
Change the password using htpasswd to the generated one
I tried it like this:
docker restart c1
a = date +%s | sha256sum | base64 | head -c 32 ; echo
docker exec -u 0 -it c1 bash 'echo cd /'
htpasswd user.passwd webdav a
And so:
docker restart c1
docker exec -u 0 -it c1 bash
cd /
a = date +%s | sha256sum | base64 | head -c 32 ; echo
htpasswd user.passwd webdav a
With the first option , I get:
bash: echo cd /: No such file or directory
With the second one, it enters the container and does nothing
I will be grateful for any help
I tried many variations of the script, which did not help me
You do not need Docker or debugging tools like docker exec just to generate an htpasswd file.
htpasswd is part of the Apache distribution, and you should be able to install it on your host system using your OS package manager. Since it just manipulates a credential file it doesn't need the actual server.
# On the host system, without using Docker at all
sudo apt-get update && apt-get install apache2-utils
# Make sure to wrap the password-generating command in `$()`
a=$(date +%s | sha256sum | base64 | head -c 32)
# Make sure to use a variable reference `$a`
htpasswd user.passwd webdav "$a"
This gives you a user.passwd file on your local system. Now when you launch your container, you can bind-mount the file into the container:
docker run -d -p 80:80 ... \
-v "$PWD/user.passwd:/usr/local/apache2/conf/user.passwd" \
httpd
The container will be immediately ready to use. If you delete and recreate this container, you do not need to repeat the manual setup step. If you need to launch multiple copies of the container, they can all have the same credentials file without doing manual steps.
The command which on line 4 on the script below seems to have an issue, intellij says
which is non-standard. Use builtin 'command -v' instead
Since which psql seems like it is not working it automatically affects line 12 and 13.
While investigating i removed line 4 then the script executed line 6 to 10 which succefully created a docker file(pg-docker) however i also need the schema.sql (line 12) and data.sql (13) to be executed. Is there an alternative command for which command(line 4)
Below is my bash Script:
#!/usr/bin/env bash
set -euo pipefail
which psql > /dev/null || (echo "Please ensure that postgres client is in your PATH" && exit 1)
mkdir -p $HOME/docker/volumes/postgres
rm -rf $HOME/docker/volumes/postgres/data
docker run --rm --name pg-docker -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=dev -d -p 432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql postgres
sleep 3
export PGPASSWORD=postgres
psql -U postgres -d dev -h localhost -f schema.sql
psql -U postgres -d dev -h localhost -f data.sql
I get the below on the problems on Intellij
line 4 complains about which command
line 6,7 and 9 complains about $HOME
line 11 complains about PGPASSWORD
which is used to find and show the full path of a command (in your script it is only used to make sure the command psql is there).
IntelliJ or probably better the defined linter for (bash) scripts suggest not to rely on an separate whichcommand but just use the builtin bash-function command -v so the line 4 would read
command -v psql > /dev/null || (echo "Please ensure that postgres client is in your PATH" && exit 1)
That said - it's most likely not your real problem. You need the PostgreSQL Client psql installed and in your PATH variable to run the commands in line 12 and 13. Exactly that's what you're checking in line 4 - regardless of using which or command -v.
How to install the psql command depends on your OS.
Batch file on WS 2008R2 Enterprise SP1, calling plink.exe (v.0.70.0.0), executing in ubuntu 16.04.4, intermittent failure Unable to read from standard input: The handle is invalid.
echo -e "youGuessedIt\n" | sudo -S nginx -t -c /home/userNoOne/Documents/nginx.conf &> /home/userNoOne/Documents/nginxResult.txt
echo -e "youGuessedIt\n" | sudo -S tail /var/log/nginx/error.log.1 >> /home/userNoOne/Documents/nginxResult.txt
echo -e "youGuessedIt\n" | sudo -S tail /var/log/nginx/error.log >> /home/userNoOne/Documents/nginxResult.txt
There is a known bug with Plink.exe that documents this failure. I'm looking for the simplest work-around:
https://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/win-plink-stdin-handle-invalid.html
I have a kiosk that shuts down every day using rtcwake, and this uses root user. I've used && to execute the boot script after rtcwake completes, however it then starts the browser as root causing problems.
This is the command I use:
echo debian | sudo -S rtcwake -m mem -u -t $(date +%s -d '3 days 7:45') && sudo -u debian -i bash $HOME/kiosk/bin/startup.sh &.
The sudo command does work to some extent. It calls the debian user, and executes the correct script, however, it still screws up my chromium preferences.
Here is the startup script:
echo debian | sudo -S hwclock -w
export HOME=/home/debian
#log boot time
echo "Booting at" $(date) >> $HOME/kiosk/bin/logs/boot.log
#echo debian | sudo -S service connman restart
echo debian | sudo -S at 15:30 -f $HOME/kiosk/bin/shutdown.sh
crontab -u debian crontab.txt
bash $HOME/git.sh
#sudo -i -u debian
#start kiosk
export DISPLAY=:0
chromium-browser --kiosk --disable-gpu
http://localhost/kiosk/Client/main.html &
#update ip
bash /home/debian/git.sh &
I'm wondering what could be causing chrome to be executed as root. I have no idea what is going wrong.
If you execute a command with sudo it will not change environment variables like $HOME. Since per user settings are stored in $HOME, this affects the executed program if it needs such configuration files. Check this for example:
sudo -u debian bash -c 'echo $HOME'
It will print the home folder of the calling user, not the home folder of the user specified trough -u. The sudo command supports the -H command line option to handle this, however if it works depends on the security police in use.
As a solution you can use the su command instead of sudo in this case:
... && su debian -c chromium
Since su itself is executed by root you won't be asked for the password.
You must enter a password to log into a new user shell.
The command needs to be modified as follows:
echo debian | sudo -S rtcwake -m mem -u -t $(date +%s -d '3 days 7:45') && echo debian | sudo -S -u debian -i bash $HOME/kiosk/bin/startup.sh &
This avoids needing a password to log in as normal Debian user, and executes the script.
Running the command
curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
does not install the tool
I was able to install it easily on my other computer running 10.9.2
STEP : 1
Make a copy of this
#!/bin/bash
TMP_FILE=/tmp/parse.tmp
if [ -e /tmp/parse.tmp ]; then
echo "Cleaning up from previous install failure"
rm -f /tmp/parse.tmp
fi
echo "Fetching latest version ..."
curl --progress-bar https://www.parse.com/downloads/cloud_code/parse -o /tmp/parse.tmp
if [ ! -d /usr/local/bin ]; then
echo "Making /usr/local/bin"
mkdir -p /usr/local/bin
fi
echo "Installing ..."
mv /tmp/parse.tmp /usr/local/bin/parse
chmod 755 /usr/local/bin/parse `
to a file named install.sh and run it in your terminal as bash install.sh. This will install you parse in your Terminal.
STEP :2
Download the Gist from this link and run the file named install.sh in your Terminal preceded by bash