tag:blogger.com,1999:blog-39414674937956283262024-03-08T14:58:40.358-08:00Linux Fireballtekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.comBlogger43125tag:blogger.com,1999:blog-3941467493795628326.post-28258132566608587742023-04-20T16:52:00.003-07:002023-04-20T16:54:13.224-07:00Initializing Postgresql server after a fresh installThese brief instructions are from Fedora 38.
<br><br>
<h4>Initialize the database</h4>
<br>
Initialize the database with this command (as root):<br>
<br>
<code>/usr/bin/postgresql-setup --initdb</code>
<br><br>
<h4>Enable the service and start it</h4>
<br>
Run these systemctl commands (as root):
<br>
<code>systemctl enable postgresql</code>
<br>
<code>systemctl start postgresql</code>
<br><br>
<h4>Allow local trust for unix and IP4 sockets</h4>
<br>
Edit the /var/lib/pgsql/data/pg_hba.conf file as root and change the local line to trust:
<br>
<code>local all all trust</code><br>
<code>host all all 127.0.0.1/32 trust</code>
<br><br>
Then, restart the service.
<br><br>
<h4>Login as user postgres and create other users and databases</h4>
<br>
<code>psql -U postgres</code><br>
<code>create role [user]</code><br>
<code>create database [user]</code><br>
<code>alter role [user] with login</code><br>
<br><br>
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-53766741892903332202023-03-31T09:52:00.000-07:002023-03-31T09:52:52.519-07:00Creating an SSL Certificate Signing Request To create a CSR, use the openssl command.
<br><br>
<code>openssl req -nodes -new -x509 -keyout server.key -out server.cert</code>
<br><br>
The -nodes option tells openssl not to use DES to encrypt the key. tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-60759604221076258342021-10-14T08:48:00.001-07:002021-10-14T08:48:45.488-07:00Comparing two Postgresql tablesTo find differences between two tables with the <b>same</b> columns, use the EXCEPT keyword. This can be extended to as many columns as are in the tables.
<br><br>
<code>
SELECT id, employee_id, effective_on, 'not in table2' AS note FROM table1 EXCEPT SELECT id, employee_id, effective_on, 'not in table2' AS note FROM table2;
</code>
<br>
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-70590411838059705272018-07-13T14:53:00.001-07:002018-07-13T14:57:28.785-07:00Online resizing of an LVM logical volume on Linux under VMWare<p>
Layer upon layer of abstraction can complicate this procedure. The common case is that a logical volume is running out of space and needs to be expanded. This can all be done non-destructively and while the volume is in use. It can be expanded by adding a SCSI disk within VMWare or by increasing the size of an existing SCSI disk in VMware. There may be some SAN level commands required first, and those will vary by the kind of SAN connected to VMWare. This specific recipe is based on first increasing the size of an existing SCSI disk in VMWare.
</p>
<h4>Step One - tell Linux to check the size of the SCSI disk that was expanded in VMWare.</h4>
<p>
Initially, Linux will not see any changes in the disk configuration. To see all the SCSI devices the system knows about, run:<br>
<code>
ls /sys/class/scsi_device/ <br>
0:0:0:0 0:0:1:0 0:0:2:0
</code>
<br><br>
Once the expanded disk is identified, enable a rescan on the device:<br>
<code>
echo 1 > /sys/class/scsi_device/0\:0\:2\:0/device/rescan
</code>
<br><br>
Then, run pvdisplay to make sure the physical volume shows the new size. Also, note in the output which volume group the physical volume is assigned to for the next step.
</p>
<h4>Step Two - make the sure the volume group shows free space</h4>
<p>
<code>vgdisplay <i>volume-group-name</i></code>
</p>
<p>
Check to verify the volume group now has free space.
</p>
<h4>Step Three - expand the logical volume</h4>
<p>
Run the following command (replacing the logical-volume with the correct name) to expand the logical volume using ALL available free space in the volume group. If that's not what you want, check the syntax of lvexpand to add the amount of space you want to use.
</p>
<p>
<code>lvextend -l +100%FREE <i>logical-volume</i></code>
</p>
<h4>Step Four - expand the Linux filesystem</h4>
<p>
Ext3/4 and XFS filesystems can be expanded
</p>
<p>
<code>resize2fs /dev/mapper/vg-name/lv-name</code><br>
OR<br>
<code>xfs_growfs /dev/mapper/vg-name/lv-name</code>
</p>
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-71973462848578590832017-11-01T10:59:00.000-07:002017-11-01T10:59:34.830-07:00Dumping PDF form fields in LinuxTo see form fields in a fillable PDF:
<br>
<code>pdftk <i>pdf-file</i> dump_data_fields</code>
<br><br>
Note the operator (dump_data_fields) comes after the PDF file name.tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-54138498782518759512017-03-06T16:39:00.000-08:002017-03-06T16:42:22.863-08:00How to dump your IpodA long time ago, in a galaxy nearby, I bought into the Apple-Unix fusion. Apple scrapped their weak OS and gave birth to OS X, essentially FreeBSD with a nice GUI. And it was good. Most of my Linux command line skills directly transferred, and I could manage Macs as easily as Red Hat boxen. But then time happened. Services started collapsing into Apple proprietary services. Config files and dot files morphed into XML registries with binary fields. Apple started fixing Unix until it was broken. I got off the bandwagon.
<br><br>
I always kept my data in neutral formats. Text, PDF, mp3. It was easy for me to transfer my data to a new system and pick up new programs, or crusty old programs. The one clinger was an ipod nano. I used my ipod in my Toyota mainly to run playlists and be able to play music when I was out of service for streaming. I spend a lot of time in the back country so being out of service is a common thing. Despite my disillusionment with Tim Cook and his wonder watch, the ipod was and is a state of the art music player. Itunes on the other hand, followed the same degrading path as OS X, becoming less usable, unfriendly, and more buggy with each new version. This became a real problem when the 5 year old ipod started to fail. Rebuilding it from scratch would not fix the issues with it and it was time to look for a new solution. Replacing that symbiotic ecosystem was not easy as I found out.
<br><br>
Where are all the ipod competitors? There are a few Chinese knock offs, but the big players have all given up. Microsoft dumped the Zune. Samsung stopped making their ipod competitor. A replacement required a hardware and software combo solution. After some trial and error, including trying one of the knock offs, I settled on Music Monkey (free) and a low profile USB flash drive. I bought a <a href="https://www.amazon.com/gp/product/B00812F7O8/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1">32 GB SanDisk Cruzer Fit</a> for $11.95 on Amazon.
<br><br>
I do development on Linux, but I have a Win10 machine for home use and game play. Media Monkey easily imported my music files and could dump them onto the Cruzer without problems. I had everything in a single flat directory. But things were not that simple. The Toyota music head (2015) would only index up to 999 files in a directory before giving up. This meant that even through my music was all on the USB flash drive, the car did not see it all. I went back and manually organized the files into directories by artist. This improved the situation, but the car created it's index not based on the physical layout (other than the 999 file restriction), but based on MP3 metadata tags. It was able to index more of the music but not everything. The work around for that was to clean up my metadata. Not an insignificant amount of work.
<br><br>
The final hurdle was to get playlists working. The car did not understand the standard playlist format from Media Monkey. What I did instead was use Genre. The Genre tag is so arbitrary that it is otherwise useless. When I want to change a playlist, I first create a true playlist in media monkey, select all the files and assign the playlist name to the Genre of all the files. Boom, done! A bonus hack is start all the Genre names with AA* so they all appear in the same place at the top of the genre index. For example, AABeatles for a Beatles playlist. It took some trial and error, but I have a better, cheaper solution for offline music and have abandoned the last vestiges of the company with the flying saucer HQ. tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-55372335068461145622017-02-28T14:04:00.000-08:002017-05-11T09:56:30.896-07:00Exim cheatsheetBradTheMad published <a href="http://bradthemad.org/tech/notes/exim_cheatsheet.php">this excellent reference for getting things done with Exim</a>.tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-69004215165370697242016-08-15T14:35:00.000-07:002016-08-15T14:35:01.785-07:00SSH<h2>SSH Client</h2>
<h4>Common client files in the ~/.ssh/ directory</h4>
known_hosts => ip/hostname and fingerprints of servers that have been seen before<br>
authorized_keys => concatenated list of public keys that can login as this user without a password
<br><br>
<h4>To generate a public/private RSA key pair (id_rsa and id_rsa.pub)</h4>
<code>ssh-keygen -t rsa -b 4096</code>
Private keys must be readable only by the user or SSH will ignore it for safety. Also, the .ssh directory must be readable only by the user.
<br><br>
<h4>To copy the public key to a server</h4>
<code>ssh-copy-id -i id_rsa.pub user@server</code>
<br>
After completion, make sure the key was appended to the .ssh/authorized_keys file on the server.
<br><br>
<h2>SSHd server</h2>
The config file is <code>/etc/ssh/sshd_config</code>
<br><br>
<h4>Best practice security settings</h4>
<ul>
<li>On public facing servers, always disable root logins with <code>PermitRootLogin no</code></li>
<li>For extra security, specifically limit the users that can login with <code>AllowUsers neo trinity</code></li>
<li>Allow login via keys with <code>AuthorizedKeysFile .ssh/authorized_keys</code></li>
<li>You can change the port that SSH listens on, but a good port scanner will find it wherever it is</li>
</ul>
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-82424093617854387132015-09-25T15:29:00.001-07:002015-09-25T15:31:06.318-07:00Pulling single tables out of a large MySQL dump fileThis is a problem I run into occasionally when I need to restore only one or two tables from a large database dump file in text format.
<br><br>
It can be done with many scripting languages, but I found a nice awk command on the <a href="https://blog.tsheets.com/2008/tips-tricks/extract-a-single-table-from-a-mysqldump-file.html">T-sheets blog</a>. To use the awk command, you need to know the names and order of the tables in the dump file. First, grep for "CREATE TABLE" to find the names and order of tables in the dump:
<br><br>
<code>grep -n "CREATE TABLE" dumpfile.sql</code>
<br><br>
The -n switch adds the line number which is not really needed. Next, plug in the name of the table you want to extract and the name of the table immediately following it:
<br><br>
<code>awk ‘/Table structure for table .table-to-extract./,/Table structure for table .table-after./{print}’ dumpfile.sql > /tmp/extracted_table.sql</code>
<br><br>
Next, I usually go in and add a "use my_database_name" command at the top and remove any unnecessary commands added by the mysqldump program. The last step is to feed the extracted table SQL to mysql.
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-43483843109177696752015-06-20T10:00:00.001-07:002015-06-20T10:00:27.351-07:00Printing from Android Phones to Epson printersThe problem of printing from mobile devices is somewhat involved. The main problem is that standards like WiFi Direct or bluetooth printing are still in early stages of deployment. Some vendors have their own solutions that work pretty well with their devices, but they tend to be islands. Google has cloud print, but that requires a dedicated print server on the local network running headless Chrome to route the print jobs. I don't know the details of Apple Cloud Print, but it probably works in a similar way, with some local device acting as the print server.
<br><br>
On my Samsung Galaxy S6, I decided to download the Epson Print Enabler from the Play Store. Once it was installed and enabled, I took the phone to close proximity of my printer, and Epson WF-3520 multi-purpose wireless inkjet and tried to print a web page from Chrome. Chrome defaults to printing to a PDF document, but I was able to select the Epson from a drop down list, deselect the pages I did not want to print and send a single page of the web site to the printer. It worked like magic.
<br><br>
This is one of the island solutions that might only work with Android phones and Epson wireless printers, but it does work without any print server set up or routing through the Internet. The Epson printer is the best wireless inkjet I've owned and is highly recommended whether you want to use the Android printing features or not.
<br><br>tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-22141717584948652092015-06-06T09:43:00.001-07:002015-06-06T09:43:06.709-07:00Limiting connections to port 80The Linux software firewall, iptables, has the ability to limit the number of concurrent connections on a specific port. This could be used as a crude DDOS defense. It won't save a web site, but it might save the server from becoming overwhelmed and unresponsive. Here is an example of limiting the number of connections on port 80 to 25. After 25 open connections, the next connection is dropped.
<br><br>
<code>
iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 25 -j REJECT --reject-with tcp-reset
</code>
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-61367914291482689362015-03-25T15:42:00.000-07:002015-03-25T16:29:14.884-07:00Simple routing in LinuxThe Linux kernel has pretty capable network routing capabilities.
<br><br>
To see the current routing table:<br>
<code>route -n</code>
<br><br>
The default gateway will have the "UG" flags shown in the output. Red Hat and CentOS systems usually have the routing table stored in /etc/sysconfig/network-scripts/ by network device (e.g., route-eth1, route-eno1). To change or modify the routing table, you must be root.
<br><br>
To add a default gateway from the command line:<br>
<code>/sbin/route add default gw ip-address eth0</code>
<br><br>
To add a static route, use the <b>ip</b> command and specify the destination and interface:<br>
<code>/sbin/ip route add 192.168.1.0/24 via 192.168.2.254 dev eno1</code>
<br><br>
To see how packets will be routed to an ip address:<br>
<code>/sbin/ip route get ip-address</code>
<br><br>tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-22773969844924465062015-01-03T09:47:00.001-08:002015-01-03T09:48:23.989-08:00Chromebook keyboard shortcutsLast year, I replaced my Android tablet with an Acer i3 Chromebook. It was one of my best technology moves of the year. I love the form factor, keyboard, built-in SSH, screen, external ports, and ability to run a native Linux distro in paravirtual machine. The only thing I didn't like about the keyboard was that is was missing a DELETE key. The fix for that is a keyboard shortcut:
<br>
<code>Alt+Backspace</code>
<br><br>
Take a screenshot with <code>Ctrl+[show windows]</code>.
<br><br>
The show windows button looks like a window with two vertical bars after it. Screenshots are saved to your Downloads directory with the date and time as PNG files.
<br><br>
Here are <a href="http://www.omgchrome.com/10-shortcuts-every-chromebook-owner-should-know/">more keyboard shortcuts from OMG Chrome</a>.
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-56939154172007752042014-08-20T13:42:00.000-07:002014-08-20T13:54:40.468-07:00Ruby on Rails scaffold generated form fieldsRails has a cool feature that generates basic CRUD screens based on command line input. It can generate a model file, a set of views, a controller, tests, and migrations. While officially shunned for production code, scaffolding may produce most of the functionality you need in parts of your application.
<br><br>
It generates views with array style form field names. For example, if your model name is "widget" and it has an attribute of "column1", the form name generated in views will be name="widget[column1]". It may not be immediately clear how to reference this field using params in the controller.
<br><br>
The answer is to reference it as a hash of hashes. A simple name="field" is referenced in the controller as params[:field]. The scaffold generated field in the above example would be referenced as <code>params[:widget][:column1]</code>.
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-40693576208449289312014-07-31T09:09:00.003-07:002014-07-31T09:10:40.643-07:00Chromebook, crouton, Ubuntu trustyI had been in the market for a low cost Linux laptop for a while, but was not overly excited about the choices. There are a small number of Linux laptop vendors, and Dell offers an Ubuntu based ultrabook at a price around $1300. That is not a low cost option.
<br><br>
Then, I found a blog post where someone had installed Linux on a chromebook. I always thought chromebooks were interesting, but limited. The ability to run Linux in a paravirtual mode sold me, but I still had issues with the performance, having used a chromebook loner earlier this year. I was waiting for the new generation of chromebooks to be released late this summer with Intel i3 processors. That would be plenty of horsepower to run Linux and Chromium at a low cost.
<br><br>
I am typing this post on an Acer C720 with the i3 and 4GB RAM ($379), just a few days out of the box. So far, I am happy with the fit and finish of the Acer, the performance, the ports (2 USB, 1 SD, 1 HDMI, Wifi, Bluetooth), and battery life. Following <a href="http://lifehacker.com/how-to-install-linux-on-a-chromebook-and-unlock-its-ful-509039343">this guide from Lifehacker</a>, using a <a href="https://github.com/dnschneid/crouton/blob/master/README.md">script from Google called crouton</a>, I installed Ubuntu in a chroot environment and am able to hot key back and forth between Linux and Chromium. It is freaking sweet!
<br><br>
If you run a crouton install with no parameters, you get Ubuntu 12 which is a couple of years old. However, there are 3 versions of Debian, a penetration testing distro called Kali, and 2 versions of Ubuntu LTS available from crouton. After some experimentation, I eventually installed Ubuntu 14 LTS (trusty) with the Unity desktop using this command:
<br><br>
<code>sudo sh -e ~/Downloads/crouton -r trusty -t unity</code>
<br><br>
It doesn't come with a lot of applications, so I need to get busy with apt-get and set up my development environment. This is the low cost Linux machine I've been wanting.tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-59137139124561500822014-04-20T11:58:00.001-07:002015-03-09T12:50:10.942-07:00Blocking and unblocking an IP using iptablesIptables is the Linux software firewall.
<br><br>
<h4>To block an IP (all ports), as root:</h4>
<code>iptables -I INPUT -s <i>ip-address</i> -j DROP</code>
<br><br>
<h4>To unblock an IP:</h4>
There are two steps. The iptables rule must be deleted by line number, so first you need to determine which rule you want to delete.
<br>
<code>iptables -L -n --line-numbers</code>
<br><br>
Next, delete the rule for the IP you want to unblock. This will delete rule number 3:
<br>
<code> iptables -D INPUT 3</code>
<br><br>
To clear all firewall rules, use the flush switch
<br>
<code> iptables -F</code>tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-18296044528206470232014-04-20T09:35:00.003-07:002014-04-20T09:35:49.563-07:00Apache processes, process size, IP clients, and statusTo help monitor apache performance, here are some useful command line recipes.
<br><br>
<h4>Show how many apache processes are running</h4>
<code>ps aux | grep [h]ttpd | wc -l</code>
<br>
The bracketed [h] prevents the grep process itself from being counted.
<br><br>
<h4>Show the average apache process size in MB</h4>
<code> ps aux | grep [h]ttpd | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'</code>
<br><br>
<h4>Show the top 10 apache client IPs by number of sockets</h4>
<code>/bin/netstat -ntp | /bin/awk '$4 ~/:(80|443)$/ {print $5}' | /bin/sed 's/.*ffff://' | /bin/cut -d: -f 1 | /bin/sort | /usr/bin/uniq -c | /bin/sort -nr | /usr/bin/head</code>
<br><br>
<h4>Show full status</h4>
<code>apachectl fullstatus</code>
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-5637884259172168912013-12-06T09:51:00.001-08:002014-10-29T06:00:50.462-07:00Mysql commands<h4>Login to MySQL</h4>
<code>mysql --user=xxx --password=xxx --database=xxx</code>
<br><br>
<h4>Dump a database</h4>
<code>mysqldump --user=xxx --password=xxx <i>dbname</i></code>
<br><br>
<h4>Dump a single table with data</h4>
<code>mysqldump --user=xxx --password=xxx <i>dbname tablename</i></code>
<br><br>
<h4>Dump a single table with only some of the data using --where</h4>
<code>mysqldump --user=xxx --password=xxx <i>dbname tablename</i> --where="db='blog3'"</code>
<br><br>
<h4>Dump a single table with data in tab separated format (for import to XL)</h4>
<code>mysqldump --user=xxx --password=xxx <i>dbname tablename</i> -T <i>path</i></code>
<br>
The -T path (example: -T /tmp) tells mysqldump where to create a tablename.sql file with the table definition, and a tablename.txt file with the tab separated data from the table.
<br><br>
<h4>Dump a single table structure without the data</h4>
<code>mysqldump --user=xxx --password=xxx --no-data <i>dbname tablename</i></code>
<br><br>
<h4>Grant all privileges on a database to a user, be sure to flush privileges after to make the security change effective immediately</h4>
<code>GRANT ALL ON db1.* TO 'username'@'localhost';</code>
<br>
<code>FLUSH PRIVILEGES;</code>
<br><br>tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-33863321114703182002013-08-20T11:24:00.001-07:002013-08-20T11:24:25.360-07:00Getting Rails variables into external JavaScript filesIt is often convenient to keep JavaScript code in external .js files and pull them into a web page using this HTML command:
<br><br>
<code><script src="external.js"></script></code>
<br><br>
In a normal rails .erb or .haml view, you can't use a rails variable value inside the external JavaScript file. The trick is to set the value in an HTML meta tag, then use JavaScript to read the meta tag after the DOM is ready. For example, in the .erb view file, use:
<br><br>
<code><meta name='railsvariable' content='<%= @railsvar %>' /%></code>
<br><br>
Then, in the JavaScript file, using the Dojo query function:
<br><br>
<code>var railsvar = query('meta[name="railsvariable"]')[0].content;</code>
<br><br>
In raw JavaScript, it would be this:
<br><br>
<code>var railsvar = document.getElementsByTagName('meta').item(property='railsvariable').getAttribute('content');</code>
<br><br>
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-91999134176117493142013-05-07T09:14:00.000-07:002013-05-07T09:14:11.119-07:00Haml commentsI've had to look this up about three times which means I should add it to the blog.
<br><br>
This technique was found at <a href="https://makandracards.com/makandra/689-know-your-haml-comments">Makandra Cards</a>.
<br><br>
To comment out code such that haml does not process it (it generates no HTML):
<br><br>
<code>-# = link_to 'foo'</code>
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-15355243783806448852012-12-05T09:03:00.001-08:002012-12-05T09:03:41.047-08:00Ruby one liners<b>One liner to edit a file in place</b>
<br><br>
This command edits a file in place, performing a global text search/replace. The -p switch tells ruby to place your code in the loop while gets; ...; print; end. The -i tells ruby to edit files in place, and -e indicates that a one line program follows.
<br><br>
<code>ruby -p -i -e '$_.gsub!(/248/,"949")' file.txt</code>
<br><br>
<b>One liner to remove DOS line endings from a file</b>
<br><br>
A Unix or Mac text file uses a single line feed character to mark the end of a line (hex 0A). Files created on DOS or Windows use two characters, carriage return and line feed (hex 0D 0A). This command edits a file in place, removing the carriage returns.
<br><br>
<code>ruby -p -i -e '$_.gsub!(/\x0D/,"")' file.txt</code>
<br><br>
<b>One liner to edit files in place and backup each one to *.old</b>
<br><br>
<code>ruby -p -i.old -e '$_.gsub!(/248/,"949")' *.txt</code>tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-40211063730725150132012-11-03T08:36:00.002-07:002012-11-03T08:37:37.714-07:00Finding files owned by a user or group<h4>To find all files from the current directory owned by user "john":</h4>
<code>find . -user john -print</code>
<h4>To find all files from the current directory owned by group "john":</h4>
<code>find . -group john -print</code>
<p>
You can also use numeric IDs (-uid or -gid) instead. The find command searches hidden files and directories automatically (those with names that start with a period).
tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-30893589882922766572012-08-11T11:07:00.001-07:002012-08-11T11:07:51.351-07:00Finding the size of directories and subdirectoriesI can't take credit for this sequence of commands. I found several variations through search engines. I apologize for not linking to the site(s) where I found it. I can't find them. However, it is useful enough to document for posterity.
<br><br>
<code>
ls -AF | grep \/ | sed 's/\ /\\\ /g' | xargs du -sh
</code>tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-72083897890590636962012-07-09T03:16:00.000-07:002012-07-09T08:38:02.097-07:00Installing Python modules<h4>Installing a Python module</h4>
Most modules come with a setup.py program that uses the <i>distutils</i> module import function to install a new module. Use this command in the module directory to install it:
<br>
<code>python setup.py install</code>
<br><br>
Successful installation should make the module available in either /usr/bin/ or /usr/local/bin/.
<br><br>
<h4>Listing installed modules</h4>
<code>pydoc modules</code>tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com0tag:blogger.com,1999:blog-3941467493795628326.post-49976808021784111562012-06-09T12:18:00.002-07:002013-12-17T14:37:43.369-08:00Crontab [classic]<b>Crontab fields</b><br />
Here is a typical crontab entry and the definition of cron fields:<br />
<code>00 03 * * * /tmp/zing.sh</code><br />
<ol>
<li>minute (00-59)</li>
<li>hour (00-23)</li>
<li>day of the month (01-31)</li>
<li>month of the year (01-12)</li>
<li>day of the week (0-6 with 0=Sunday)</li>
<li>program or command to run</li>
</ol>
An asterisk (*) in any field means run every time for this field.<br />
Ranges (X-Y) and steps (X-Y/Z) can also be defined. <br />
<br />
<b>Special @reboot option</b>
<br>
Recent versions of cron support @reboot instead of time and day settings to run a command after boot. For example:
<br>
<code>@reboot /usr/bin/command-to-run</code>
<br><br>
I am not sure if I like this option, compared to using system start up scripts, like /etc/rc.d/rc.local.
<br><br>
<b>User crontabs (including the root user)</b><br />
To edit a user crontab (including root):<br />
<code>crontab -e</code> <br />
To delete a crontab:<br />
<code>crontab -r</code> <br /><br />
User crontabs are stored as text files in /var/spool/cron/.<br /><br />
<b>System crontab</b><br />
The system crontab is stored in /etc/crontab. It can be changed (as root) with a text editor. <br />
The system crontab has one extra field before the program to run, which is the user to run the command as (usually root).tekewinhttp://www.blogger.com/profile/10230830520110635922noreply@blogger.com2