Categories
Linux shell

Split PDF to individual images

[et_pb_section admin_label=”Section” fullwidth=”on” specialty=”off”][et_pb_fullwidth_post_title admin_label=”Fullwidth Post Title” title=”on” meta=”on” author=”off” date=”on” categories=”on” comments=”off” featured_image=”on” featured_placement=”background” parallax_effect=”off” parallax_method=”on” text_orientation=”center” text_color=”dark” text_background=”on” text_bg_color=”rgba(255,255,255,0.9)” module_bg_color=”rgba(255,255,255,0)” title_all_caps=”off” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_fullwidth_post_title][/et_pb_section][et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

I needed to get the images of my rent payments from the back of my bank statements for the past few months, but all the bank statements are in PDF format with multiple pages. I’m sure there’s some very sophisti-ma-cated solutions to this but here’s something simple that works.

you need ghostscript for this FYI.

convert -density 400 Statement.pdf -scale 1800x1000 statement_%d.jpg

[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”bottom above footer” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][et_pb_divider admin_label=”Divider” color=”#ffffff” show_divider=”off” divider_style=”solid” divider_position=”top” hide_on_mobile=”on”]

[/et_pb_divider][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[jetpack-related-posts]

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

Categories
Linux shell

Bash killer one liners

[et_pb_section admin_label=”Section” fullwidth=”on” specialty=”off”][et_pb_fullwidth_post_title admin_label=”Fullwidth Post Title” title=”on” meta=”on” author=”off” date=”on” categories=”on” comments=”off” featured_image=”on” featured_placement=”background” parallax_effect=”off” parallax_method=”on” text_orientation=”center” text_color=”dark” text_background=”on” text_bg_color=”rgba(255,255,255,0.9)” module_bg_color=”rgba(255,255,255,0)” title_all_caps=”off” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_fullwidth_post_title][/et_pb_section][et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”bottom above footer” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][et_pb_divider admin_label=”Divider” color=”#ffffff” show_divider=”off” divider_style=”solid” divider_position=”top” hide_on_mobile=”on”]

[/et_pb_divider][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[jetpack-related-posts]

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section][et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text”]

We sometimes need to find a process and kill it regularly, so why not automate it? well its not exactly straight forward when you automate things. you don’t want to accidentally kill random processes etc. so here’s a nice clean way to find and kill a process a couple of different ways.

First if you have a process id via a pid file (the way lane)

kill $(cat /path/to/PID-file)

now if you don’t have that you can still get it and do this via the process name

kill $(ps aux | grep '[p]rocess name' | awk '{print $2}')

or

kill $(ps aux | awk '/[p]rocess/ {print $2}')

PS the reason for the [] around the first char is so the look up command itself doesn’t show in the list.

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

Categories
Linux shell

Linux su with custom shell

I have some server only users for things like CI or media streaming that I have removed shell access from for security. sometimes however I need to login to them to test something or fix something. well here’s a very easy way to su over to them without setting their shell to something else and then setting it back.

Normally you would use

<pre lang=’bash’>su username</pre>

instead just use

<pre lang=’bash’>su -s /bin/bash username

Categories
Linux shell

Padding File names with zeros

need to pad some file names with zeros? couldnt be simpler!

 

for f in foo[0-9]*; do mv $f `printf foo%05d ${f#foo}`; done
rename 's/\d+/sprintf("%05d",$&)/e' foo*
Categories
Linux shell

Remove spaces or Edit chracters in filenames

Needed  to remove spaces from filenames, so here we are 🙂

for file in *.mp3; do mv "$file" `echo $file | sed -e 's/  */_/g' -e 's/_-_/-/g'`; done

or replace all spaces by _ using perl

ls *.bed |perl -ne 'use File::Copy;chomp;$old=$_;s/\s+/_/g;move($old,$_);'

remove underscores

rename 's/2012mp3/2012/' *.mp3

Remove the letters mp3 from middle fo filename say in case of 123-20121mp3.mp3 or some such

for i in *.mp3; do mv $i ${i//[[:punct:]]/}; done

remove punctuations from filename. WARNING it will also remove the . from extension names.

for foobar in *.mp3 ; do
temp=`echo "$foobar" | cut -c 2-`
mv "$foobar" "$temp" ;
done

remove first X characters from file name. change the 2 to any number to change the first characters removed. the formula for that is 1 + actual number. make sure to change the extension.

rename 's/1234/12-34/' *.mp3

remove some character from the middle of the file name, in this case the dash ( – ).

Categories
General Linux shell

Aptitude installed package list

Today I got a new VPS… well great but now I need to install a bunch of new packages and libraries and helper apps. how do I remember it all? did I have python 2.6 or 2.7? not to mention which boost libs did I install? well here.s a couple of ways to deal with this issue of whats on my installed package list.

Using dkpg and apt-get

dpkg –get-selections > selections.txt

Scp / email / copy to USB or copy it bit by bit, whatever floats your boat. Move to new machine.

dpkg –set-selections < selections.txt
apt-get update
apt-get upgrade

voilà it should be ok. but there’s a lot of clutter, like libraries and dependencies that were needed on old machine and might not be needed again. so how to find a cleaned up list? or alteast one that shows the automated installed? there’s always aptitude Smile its simpler in syntax and better imho

Using Aptitude

aptitude search '~i'

which gives you aresult of all your packages like :

i   udev                                                                                               – /dev/ and hotplug management daemon
i A unattended-upgrades                                                                                – automatic installation of security upgrades
i   upstart                                                                                            – event-based init daemon
i A usbutils                                                                                           – Linux USB utilities
i   util-linux                                                                                         – Miscellaneous system utilities
i   vim                                                                                                – Vi IMproved – enhanced vi editor
i   vim-common                                                                                         – Vi IMproved – Common files
i   vim-runtime                                                                                        – Vi IMproved – Runtime files
i   wget                                                                                               – retrieves files from the web

This of course scrolls all the packages past your view very quickly and can be …. hard on those of us that cant read 10000 words per minute. You can always output the results to a text file, note in my example I’m using the date command to insert current date and time into the file name, you can run this with a cron job to have a snapshot of your packages at a given time.

aptitude search '~i' > installed_packages_$(date +%F_%R).txt

Or if you just want a temp text file you can output to less or vim the same way.

aptitude search '~i' | less
aptitude search '~i' | vim

and if you want you can even grep / search / parse it on the fly like so

aptitude search '~i' | grep -i "X11"

i A libxpm4                         – X11 pixmap library
i A libxrandr2                      – X11 RandR extension library
i A libxss1                         – X11 Screen Saver extension library
i A libxt6                          – X11 toolkit intrinsics library
i A libxtst6                        – X11 Testing — Record extension library
i A libxv1                          – X11 Video extension library
i A libxxf86dga1                    – X11 Direct Graphics Access extension libra
i A libxxf86vm1                     – X11 XFree86 video mode extension library
i A tk                              – Toolkit for Tcl and X11 (default version)
i A tk8.6                           – Tk toolkit for Tcl and X11 v8.6 – windowin
i A x11-common                      – X Window System (X.Org) infrastructure
i A x11-utils                       – X11 utilities

questions? comments? don’t hesitate to ask!