Friday, June 3, 2016

cancel script completely on ctrl-c

I found this question interesting: basically how to cancel completely a script and all child processes :


You do this by creating a subroutine you want to call when SIGINT is received, and you need to run trap 'subroutinename' INT.
Example:
#!/bin/bash

int_handler()
{
    echo "Interrupted."
    # Kill the parent process of the script.
    kill $PPID
    exit 1
}
trap 'int_handler' INT

while true; do
    sleep 1
    echo "I'm still alive!"
done

# We never reach this part.
exit 0
 
Taken from: http://serverfault.com/questions/328089/ctrl-c-in-bash-scripts 

Saturday, May 14, 2016

linux root user aliases

So I was getting crazier about an email bounce I was receiving, and I didnt know the cause.

It turns our that in /etc/aliases file, you can configure the alias to the users...

Wednesday, February 10, 2016

boot ubuntu 11.04 desktop direct into console (text) but switch to GUI whenever you want

I followed this steps to boot directly into console mode... After lofin, the command startx shows the GUI..

taken from: http://askubuntu.com/questions/74645/possible-to-install-ubuntu-desktop-and-then-boot-to-no-gui


 did following
Step 1 First update your repository by running
sudo apt-get update
Step 2 There is some bug in old version of lightdm, so we need to upgrade the same. To do so run,
sudo apt-get install lightdm
Step 3 Now we have to modify grub config. Step 3a Open /etc/default/grub with your faviourite editor and change
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT="text"
Step 3b Also comment GRUB_HIDDEN_TIMEOUT=0 This line is for unhiding the GRUB menu
Step 4 Now we will upgrade GRUB configuration
sudo update-grub
Step 5 Ubuntu 11.10 Desktop edition use lightdm for GUI. We need to disable the same
sudo update-rc.d -f lightdm remove
Step 6 Now restart your machine.

Monday, February 8, 2016

script to push to Amazon Elastic Beanstalk (EB) using the CLI and Git with downtime (swapping environments)

I wanted to automate pushing to my Elastic Beanstalk Amazon environment...

here is the simple script I came up with:

requirements:
- you should be able to upload a new version already using Git
- have the EB CLI 3.7.2 (Python 3.4.3) configured in the directory where you are running this script

- copy this script into the directory that you are going to upload
- give the script execution permissions
- eb list should have a current environment (depicted with a '*')

#!/bin/bash
set -e
#get the current environment
/usr/local/bin/eb list > temp_environment
temp_environment=$(grep \* temp_environment | cut -f2 -d" ")

echo
echo
echo "detected environment ->$temp_environment<-"
echo "subtitute this environment y/N"

read answer

if [ "$
answer" =  "y" ]; then
        a=1
else
        echo "your answer was $
answer. byee!"
        exit 1
fi

echo "substituting environmet with current version"

echo
echo

sufijo=`date +%a%y%m%d%H%M%S`

ambiente_sin_sufijo=$(echo $temp_environment | cut -d"-" -f1)
sufijo_ambiente=$(echo $temp_environment | cut -d"-" -f2)

dayname=$(echo $sufijo_ambiente | cut -c1-3)
year=$(echo $sufijo_ambiente | cut -c4-5)
mon=$(echo $sufijo_ambiente | cut -c6-7)
day=$(echo $sufijo_ambiente | cut -c8-9)
hour=$(echo $sufijo_ambiente | cut -c10-11)
min=$(echo $sufijo_ambiente | cut -c12-13)
sec=$(echo $sufijo_ambiente | cut -c14-15)

set -x

echo "New version uploaded to EB: `date`" > gitlog.temp
echo ""  >> gitlog.temp
echo "The files that changed since last time are:"   >> gitlog.temp
echo ""   >> gitlog.temp

set -f
git log --name-only --no-color --graph '--pretty=format:%h - %s' --abbrev-commit --since "20$year-$mon-$day $hour:$min:$sec" >> gitlog.temp


ambiente_final="prod"-"$sufijo"

echo "Deploying to: $ambiente_final and then swapping with: $temp_environment"
echo "do you wish to continue? s/N"

read respuesta

if [ "$respuesta" =  "s" ]; then
        a=1
else
        echo "su respuesta fue $respuesta, entonces salimos. chao!"
        exit 1
fi


set -x

eb clone "$temp_environment" -n "$ambiente_final" --timeout 15 || exit 1
eb deploy "$ambiente_final" || exit 1
eb swap "$temp_environment" -n "$ambiente_final" || exit 1
eb use "$ambiente_final" || exit 1

set +x

echo
echo
echo
echo FINISHED !!!
echo
echo
echo "Remember to execute -> eb terminate $temp_environment <-"

mail -s "New version" -r "Auto Uploader<no-reply@mail.com>" myemail@mail.com < gitlog.temp

rm gitlog.temp

send text file contents throught mail in bash mail



turns out it is quite simple:

for example:

mail -s 'Uptime Report' you@mail.com -c copy@mail.com < /tmp/output.txt





taken from: http://www.cyberciti.biz/faq/email-howto-send-text-file-using-unix-appleosx-bsd/

Monday, November 30, 2015

using the COPY command in psql client (postgresql)

Useful to export/import data

Here is the syntax for COPY, as returned by the 8.3 client:
db=# \h COPY
Command:     COPY
Description: copy data between a file and a table
Syntax:
COPY tablename [ ( column [, ...] ) ]
    FROM { 'filename' | STDIN }
    [ [ WITH ] 
          [ BINARY ]
          [ OIDS ]
          [ DELIMITER [ AS ] 'delimiter' ]
          [ NULL [ AS ] 'null string' ]
          [ CSV [ HEADER ]
                [ QUOTE [ AS ] 'quote' ] 
                [ ESCAPE [ AS ] 'escape' ]
                [ FORCE NOT NULL column [, ...] ]

COPY { tablename [ ( column [, ...] ) ] | ( query ) }
    TO { 'filename' | STDOUT }
    [ [ WITH ] 
          [ BINARY ]
          [ OIDS ]
          [ DELIMITER [ AS ] 'delimiter' ]
          [ NULL [ AS ] 'null string' ]
          [ CSV [ HEADER ]
                [ QUOTE [ AS ] 'quote' ] 
                [ ESCAPE [ AS ] 'escape' ]
                [ FORCE QUOTE column [, ...] ]

Sunday, November 29, 2015

Re Blog - Remove the Endnote Separator Line in Word 2013

I finally found a way to remove the annoying end note separator (line) in Word 2013

It was here:https://uknowit.uwgb.edu/page.php?id=50456

  1. Go to View->Draft
  2. References->Show Footnotes
  3. Delete the footnote separator
Voilà!

Remove the Endnote Separator Line in Word 2013

Follow these steps to remove the Endnote separator line in Word 2013.
  1. Below is an example of an endnote separator line. (Below the words "Human Resources") *Note the endnotes are in green.

    Endnote1.png
  2. Select the View tab. From the Views group, select Draft.

    Endnote2.png
  3. To display the Endnote options, select the Reference tab, and then "Show Notes" from the Footnotes group.

    EndNote3.png


  4. From the Endnotes drop-down box, select "Endnote Separator".  Select the separator line and press your delete key.

    Endnote4.png


  5. Switch back to Page Layout view and note that the separator line has been deleted.

    Endnote5.png

Wednesday, September 30, 2015

Rsync tricks and how to rsync only one type of files by extension

Rsync is a wonderful tool. It has many options.

But to sync only a file type among many files in a dir eluded me.

After some googling I found this command:

rsync -rv --include '*/' --include '*.js' --exclude '*' --prune-empty-dirs Source/ Target/

I found it on this blog: https://silentorbit.com/notes/2013/08/rsync-by-extension/

How to rsync only one type of files by extension

Having a file structure full of various file types you want to sync only files of one type into a new location.
rsync -rv --include '*/' --include '*.js' --exclude '*' --prune-empty-dirs Source/ Target/
This will generate the same structure found in Source into Target but only including the JavaScript(.js) files.
Note the usage of ' around the arguments containing * since we don't want it to be expanded in a bash shell.
The first --include '*/' is to make sure sub-directories are scanned. This would also include all directories does not include the file you want resulting in empty directories in Target. To remove these empty directories we use --prune-empty-dirs
The --include '*.js' is rather self explanatory, and you can add more as you need.
Finally we exclude all other files we don't want using --exclude '*'


Thank you very much!

cancel script completely on ctrl-c

I found this question interesting: basically how to cancel completely a script and all child processes : You do this by creating a subro...