Posts

Showing posts with the label shell scripts

Redis user permissions (ACL) and python connection

 Recently, I was working on setting up a redis cluster along with separate users for readwrite and readonly. I setup the readonly user using the below privileges (ACLs):   user redisreadonly on >mySuperSecretPassword ~* resetchannels -@all +@read +ping +asking   Once this is setup, I wrote a simple program in python to connect to the redis cluster using the readonly credentials and print the number of keys.   #!/usr/bin/env python3 """ pip3 install redis """ from redis.cluster import RedisCluster, ClusterNode # ─────── Cluster connection ─────── startup_nodes = [ ClusterNode("redis_host_1", 6379), ClusterNode("redis_host_2", 6379), ClusterNode("redis_host_3", 6379) ] rc = RedisCluster(startup_nodes=startup_nodes,decode_responses=True,username='redisreadonly',password='mySuperSecretPassw...

WGET shell Script for downloading patches

What I have to offer this time is a script using which you can download patches using WGET from Meta.....oops, from My Oracle Support, I should say! This script needs (or accepts) the following parameters: 1. Me...oops...MOS Username 2. MOS (I got it right this time!) password 3. Patch file name 4. ARU Number You can get 3 and 4 in the following way: Using MOS: Query for the particular patch, click on the download link, click on WGET Options on the left side bottom corner and then copy the WGET script to clipboard. That script will have both the patch name and the ARU number. Using HTML (supporthtml.oracle.com): Query for the particular patch, click on the patch, then RIGHT CLICK on the patch zip file link and click on copy shortcut in IE (or copy link location in Mozilla Firefox). This link will have both the patch file name and the ARU number. Using the classic patches window: Query for the particular patch, then RIGHT CLICK on the DOWNLOAD button and click on copy shortcut in IE (or...

Flower brackets {} and variables in UNIX - A perfect match

When passing a variable in unix, the general convention is to use $variable . Although this does suffice in most cases but in some rare cases, it gives connotations totally different than what was originally intended, as shown in the below example. The requirement Copy all files ending with ver to ver_old. For example, suppose I have a file called formver, I would like to copy it to formver_old. The code below is the code that I wrote to achieve the above requirement. for i in `ls *ver` do cp -p $i $i_old done The pitfall A cursory glance at the code indicates that it should run smoothly like a river. But it doent' and herein lies the catch. Let's have a look at the error and figure out what exactly is wrong with the above code. __________________________________________________________________ $ for i in `ls *ver` > do > cp -p $i $i_old > done cp: Insufficient arguments (1) Usage: cp [-f] [-i] [-p] [-@] f1 f2 cp [-f] [-i] [-p] [-@] f1 ... fn d1 cp -r-R [-H-L-P] [-f] [...

Shell script to monitor processes

Many a time, one is faced with a situation where one needs to monitor a process to its completion. For example, if one is performing a clone, one has to copy the source files to the target or if one is performing a backup of any instance, the cp or tar commands that one has fired has to be monitored to its completion. I generally use a customised script (as below) during those situations to monitor the processes. while true do ps -fu <owner_of_the_process> grep <cp or rman or process_id> wc -l printf "\n\nPress Ctrl+C to exit this loop.......\n\n" sleep <the_number_of_seconds_this_process_should_sleep> done

Find the UNIX Process ID given a port number

One of my colleagues had started the MWA server (telnet server) and it was running on port number 9198. However, when I queried the processes (ps -ef | grep mwa), I could not find the process which had kick started the MWA server. This had me thinking and I resolved to find the process ID. However, the utility lsof was not installed on the OS (Sun Sparc Solaris 5.10) . When I probed further (googled! actually), I found a script on onlineappsdba , which I found helpful. I had to modify that script suitably to exclude processes not owned by the current user. I also referred another blog , to complete my script. ______________________________________________________ # # Make sure the logfile directory exists # if [ ! -d ${HOME}/bkp/log ]; then mkdir -p ${HOME}/bkp/log fi; if [ $# -ne 1 ]; then echo "To run the program, please provide the port number as the arguement" printf "\n\t ${usage} \n\n" exit 1; fi port_num="$1" echo printf "\n Finding the...

Popular posts from this blog

EXCEPTION_ACCESS_VIOLATION in Jinitiator and IE crashes

Version of mod_security with EBS 11.5.10.2

Read a file and extract specific lines using Native Ansible Modules