Tag: bash

  • Getting the Last Modification Timestamp of a File with Stat

    If we want to get just the date modified, for a file, in a format of our choosing. This can be done with a utility called stat. The syntax is as follows: stat -f -t “” In this example, we are printing just the date created in the format YYYYMMDD_HHMMSS. stat -f “%Sm” -t “%Y%m%d_%H%M%S” […]

  • Using the Linux Command Line to Find and Copy A Large Number of Files from a Large Archive, Preserving Metadata

    One of my recent challenges is to go through an archive on a NAS and find all of the .xlsx files, then copy them; preserving as much of the file metadata (date created, folder tree, etc) as possible, to a specified folder.  After this copy, they will be gone through with another script, to rename […]

  • Appending to a Remote File via SSH

    Most LINUX users know how to copy and overwrite a file from one server to another; but it can also be useful to directly append to a file, without having to login to the remote server and make the changes manually. This does not appear to be possible with the commonly used SCP utility; however, […]

  • Fixing Performance Problems on Your JBoss Web Apps By Diagnosing Blocked Thread Issues

    I was once perplexed by a bizarre performance issue, I encountered at seemingly random intervals, in an application I help to maintain. The application kept freezing up, without any log messages to use for diagnosis. This was very frustrating, because it meant the application server typically had to be restarted manually to restore service. After […]

  • When a List of Files is Too Long for a Typical “rm” Command

    I was on a client’s reporting server and noticed that an “ls” of their report logs took about 10 minutes. The directory had a log for every report run since June 2010, which is around 1.3 million files! Here’s a transcript of the error: [root@morpheus log]# pwd /home/morpheus/tools/birt-runtime-2_0_1/Report Engine/log You have new mail in /var/spool/mail/root […]

  • RSYNC a File Through a Remote Firewall

    One of my recent tasks was to set-up a new automatic backup script, which dumps out the MySQL database on the remote host at a regular time, at a later time, it is RSYNC’d from the backup server through a remote firewall. I must say that I was a little surprised, to discover that the […]

  • Quick and Easy Regular Expression Command/Script to Run on Files in the Bash Shell

    I often find it necessary to run regular expressions on, not just one file; but instead a range of files. There are perhaps dozens of ways this can be done, with varying levels of understanding necessary to do this. The simplest way I have encountered utilizes the following syntax: perl -pi -e “s///g” Here is […]

  • How To Execute a Script After a Running Process Completes

    Most people who are familiar with Linux, realize that there are ways of chaining processes to run one after another. Typically this is done by writing a script, or using && to daisy chain additional commands on command line. There is, however, another way to do this; if you’ve already issued a command and want […]

  • Sending Mail in Shell Scripts via an External Server with Nail

    If you’ve ever tried sending email via the command line, using the mail utility, you may find that the method can be unreliable in some cases.  The email messages are often intercepted by spam bots, filtered by security programs, etc.  A more elegant and stable alternative, is to use your existing email server to send […]

  • Bash Shell Script to Convert All MySQL Tables to use the Innodb Engine

    The following, when run in the Bash shell, will convert the engine for all of your MySQL tables to InnoDB. mysql -B -N -e “SHOW TABLES” -u –password= | while read table; \ do \ echo “+ Converting Table $table”; \ mysql -B -N -e “alter table $table engine=innodb” -u –password= ; \ done; Often, […]