execute commands as user after Vagrant provisioning

You should be able to do this using the Vagrant Shell provisioner, e.g. Vagrant.configure(“2”) do |config| $script = <<-SCRIPT rbenv install 2.0.0-p353 rbenv global 2.0.0-p353 gem update –system yes | gem update gem install rdoc gem install rails pg SCRIPT config.vm.provision “shell”, inline: $script, privileged: false end The key is to specify privileged: false so … Read more

Importing functions from a shell script

According to the “Shell Builtin Commands” section of the bash manpage, . aka source takes an optional list of arguments which are passed to the script being sourced. You could use that to introduce a do-nothing option. For example, script.sh could be: #!/bin/sh foo() { echo foo $1 } main() { foo 1 foo 2 … Read more

How do I measure duration in seconds in a shell script?

Using the time command, as others have suggested, is a good idea. Another option is to use the magic built-in variable $SECONDS, which contains the number of seconds since the script started executing. You can say: START_TIME=$SECONDS dosomething ELAPSED_TIME=$(($SECONDS – $START_TIME)) I think this is bash-specific, but since you’re on Linux, I assume you’re using … Read more

How to get remote file size from a shell script?

You can download the file and get its size. But we can do better. Use curl to get only the response header using the -I option. In the response header look for Content-Length: which will be followed by the size of the file in bytes. $ URL=”http://api.twitter.com/1/statuses/public_timeline.json” $ curl -sI $URL | grep -i Content-Length … Read more

How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?

Print lines between PAT1 and PAT2 $ awk ‘/PAT1/,/PAT2/’ file PAT1 3 – first block 4 PAT2 PAT1 7 – second block PAT2 PAT1 10 – third block Or, using variables: awk ‘/PAT1/{flag=1} flag; /PAT2/{flag=0}’ file How does this work? /PAT1/ matches lines having this text, as well as /PAT2/ does. /PAT1/{flag=1} sets the flag … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)