Category Archives: Linux

Linux – Preserve Environment Variables when using sudo

Sometimes we may want to preserve the environment variables of the original user when using sudo.

If you want to preserve all env variables, you could use the -E option. But use it with caution.

sudo -E bash -c 'echo $PATH'


A better approach is to list those env variables which u want to preserve in the sudoers config file. For example, i want to keep the HTTP_PROXY and HTTPS_PROXY.

Defaults env_keep +="HTTP_PROXY"
Defaults env_keep +="HTTPS_PROXY"


So every time you use the sudo command, the HTTP_PROXY and HTTPS_PROXY are kept.

Done =)



collectd – Cannot send out matrics

collectd is a statistics gathering tools which helps system admin to analysis the system conditions. It includes both server and client implementations. The collectd client send metrics to the collectd server.


I installed the collectd on a CentOS 7 machine and try to send the metrics to a Graphite instance. But no matter how i changed the setup, the Graphite couldn’t receive any data. Finally, i realized that it is blocked by the SELinux policy.
Continue reading collectd – Cannot send out matrics

Ubuntu – Install Monit

Monit is a opensource monitoring tool on Unix system. The simplest use case would be restarting your service if there is failure.

On Ubuntu, simply run apt-get to install Monit.

sudo apt-get install monit


The Monit folder is at /etc/monit. Before you can read anything from Monit, create the /etc/monit/conf.d/monit.conf in order to setup the Monit web interface.

set httpd port 2812 and
  use address localhost
  allow localhost

Continue reading Ubuntu – Install Monit

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

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?