Posts Tagged ‘script’

API and RedHat Network

11/08/2011

If you use RedHat Enterprise Linux in a big environment, you probably
use RedHat Network (RHN) as well.

RHN has a very well documented API, which can be used for all tasks
you want to do.

Here is a small script I wrote to list out all of our systems and when
they last checked in:

#!/usr/bin/python

import xmlrpclib
import getpass
from sys import stderr
import sys

RHN_URL = “https://rhn.redhat.com/rpc/api”

# Using stderr so redirect of the script to a file still works for prompts:
stderr.write(‘Please input your RHN username: ‘)
stderr.flush()
u = raw_input().rstrip(‘n’)
p = getpass.getpass(stream=sys.stderr)

client = xmlrpclib.Server(RHN_URL, verbose=0)
key = client.auth.login(u, p)
list = client.system.listUserSystems(key)

for group in list:
sysname = group.get(‘name’)
sysid = group.get(‘id’)
last_checkin = group.get(‘last_checkin’)
print ‘{0} – {1} ‘ .format (sysname, last_checkin)

client.auth.logout(key)

Hope that might be useful for someone else.

For more info on RHN’s APIs:
https://access.redhat.com/knowledge/docs/Red_Hat_Network/API_Documentation/

Move into folders

01/02/2010

Often when you download something, for instance movies, it is a big pack of many movies, and they are all in one folder as .avi files or something like that. You might want all of those in their own separate folder to use with f.ex. XBMC, and it can be a tedious task to make a folder for each movie, and move them into that folder.

Well here is the script to do it, filled with comments to explain what is happening. Hope someone finds it useful.

First: This is the quick and dirty oneliner to do it if you are sure there are only files with extensions in the dir, it’s without any error-checking:
IFS=$’n’;for f in `ls -1`; do mkdir “${f%.*}”;mv “${f}” “${f%.*}/”;done

The whole script is attached, with an abundance of comments describing what’s happening.

pakkut.sh

12/31/2009

Et lite script for å gå ned i hver underkatalog, se etter filer som
slutter på .rar, og pakke de ut.  Så spør den om du vil slette “*r??
*sfv” hvorpå den evt. sletter de.

Kjekt når man laster ned noe som kommer som en haug med underkataloger
med rar’et innhold.


%d bloggers like this: