Tag Archives: Shell

Apache Ant – Run piped command in exec task

The Ant <exec> task allows us to run shell command in Ant script. We could provide input arguments like the following example which prints today’s weekday.
build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="Ant Piped Commands" default="today" basedir=".">
  <target name="today">
    <exec executable="date" outputproperty="weekday">
      <arg value="+%A" />
    </exec>
    <echo message="Today is : ${weekday}"/>
  </target>
</project>

ant-exec-piped-commands-1
Continue reading Apache Ant – Run piped command in exec task

Python – Execute shell command

Example run ls -l

import subprocess

# Execute ls -l
output = subprocess.Popen(["ls", "-l"], stdout=subprocess.PIPE).communicate()[0]

# Print the stdout
print output

 

Done =)

Reference:

Artifactory – Upload artifact through command line

Jenkins works well with Artifactory and the built artifact will be upload to the Artifactory repository automatically.

One day, i found that the artifact is built but it is not uploaded. The Linux server doesn’t have the desktop interface so i couldn’t upload the artifact through browser. An alternative way is to use the curl command to post the artifact to the repository.

curl -X POST <target url> --data <artifact>

 

Example:

curl -X POST http://localhost:8081/artifactory/dev-snapshot-local/eureka-v0.0.1.tar.gz --data eureka-v0.0.1.tar.gz

 

Done =)

Reference: StackOverflow – How do I deploy a file to Artifactory using the command line

Housekeeping Puppet Master

Yesterday i used a Puppet master as an example to talk about purging old files on Linux.

Of course we can setup a cron job and run the shell command daily for housekeeping. But as we are using Puppet, we don’t we do that thru Puppet manifest?

tidy { 'puppet::reports':
  path => '/var/lib/puppet/reports',
  matches => '*.yaml',
  age => '14d',
  backup => false,
  recurse => true,
  rmdirs => false,
  type => 'ctime',
}

 

The above tidy type will delete those .yaml which is older than 14 days.

Done =)

Reference: Google Groups – Purge puppet’s reports

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

ImageMagick – Manipulate Image Files by Shell Commands

ImageMagick is built on Ghostscript which i have introduced in the following post previously.
Ghostscript – Convert PDF Cover/Page into PNG

I am working on my Rails project with the Paperclip gem which requires ImageMagick. Installation of ImageMagick in Ubuntu is very simple. Just grab it by apt-get. Continue reading ImageMagick – Manipulate Image Files by Shell Commands