Tag Archives: Linux

Linux – Delete files which are older than N days

One day i found that the Puppet master is running out of space and then i realize that there is a lot of run reports in YAML format located @ /var/lib/puppet/reports. I want to delete the old reports for releasing the disk space.

So i move to the /var/lib/puppet/reports directory and execute the following line to recursively remove any .yaml which is older than 14 days.

find $d -type f -name \*.yaml -mtime "+14" -exec rm -f {} \;

 

A few years ago i had a post about a housekeeping shell script which is quite similar to the above approach.

Done =)

Reference: Google Groups – Purge puppet’s reports

Ubuntu – Install Node Ver­sion Man­ager globally for all users

The Node Ver­sion Man­ager(nvm) could help you to manage multiple Node.js installations. The following steps are executed from root account.

1. Install the required packages.

apt-get install build-essential openssl libssl-dev curl

 

2. Create a new user group and add those users which are allowed to manage Node.js installation. The following command create a new group called dev.

groupadd dev

Continue reading Ubuntu – Install Node Ver­sion Man­ager globally for all users

Shell Script – Check file owner and other attributes

Here is a simple shell script which would read a user input and return you the owner and group of the input path.

check_owner_and_group.sh

#!/bin/sh

echo "Please enter a file/folder path:"
read target_path
echo "You have entered $target_path"

if [ -e $target_path ]; then
  target_owner=$(stat -c %U $target_path)
  target_group=$(stat -c %G $target_path)

  echo "$target_path owner is: $target_owner"
  echo "$target_path group is: $target_group"
else
  echo "$target_path is not a valid path"
fi

Continue reading Shell Script – Check file owner and other attributes

Yum – Check for update of repositories

When a new rpm is added to a yum repository server, the cache in the client machine makes the new rpm unreachable. To check for update of repositories, run the following command in the client.

  • yum clean expire-cache

 

Then you can try to search for your new rpm by

  • yum list <new rpm package>

 

Done =)

Reference: How do I get yum to see updates to a local repo without cleaning cache?

Linux – Re-sign an rpm package

Working on the Puppet manifest to install the newrelic-sysmond package to all the nodes. I want to host the newrelic-sysmond.rpm on the company repository server but in that case the i have to re-sign the rpm.

What i need to do is to download the rpm from the New Relic repository, move it to the RPM build server and run the following command.

  • rpm --resign newrelic-sysmond-1.3.1.437-1.x86_64.rpm

 

You will be prompted to enter the passphrase and that’s it.

Done =)

Reference: Maximum RPM – Signing Packages

PowerShell – Get command path like the “which” command in Linux

I have installed Sublime Text 3 with the Git package but it keeps prompting Git command not found in the PATH variable. Before i update the PATH, i have to figure out where is my Git command.

In Linux, we can get the path of a specific command by which [comamnd].
ex. ~$ which git
powershell-which-1
Continue reading PowerShell – Get command path like the “which” command in Linux