Category Archives: Programming

Borne Shell Script – This is used for taking a formatted user list and adding users.

Posted on by .

# /bin/bash
# Borne Shell Script
# This is used for taking a formatted user list and adding users. Run as root.
# Command line usage: this_script name_of_user_list_file
# Example line of file-input:”     200780958   AGARWAL, SAURABH”
# Example line of file-input:”     203660406   MASON, DOUGLAS E”
# Example line of file-input:”     203624328   MCCAULEY, MATTHEW J.”
# Example line of file-junk: ” DAYS  TR    PERIOD  D                  SEM HOURS =   3.0″
#
#GREP filters out the lines with 9 consecutive digits.
grep “[0-9]\{9\}” $1 > raw_uu_list;
#Change spaces,tabs,commas,and periods, all to dashes.
cat raw_uu_list | tr ‘ ‘ ‘-’ | tr ‘,’ ‘-’ | tr ‘.’ ‘-’ > uu_list_C;
#Trim the userlist so the junk displayed on the side is not there.
cat uu_list_C | cut -b 0-46 > uu_list_C_T;
#Add a “-x” onto every line, for anyone who does not have a middle name.
cat uu_list_C_T | awk -F : ‘{print $0″-X”;}’ > uu_list_C_T_X;
#Normalize columns by replacing the blocks of dashept name_of_user_list_file
# Example line of file-input:”     200780958   AGARWAL, SAURABH”
# Example line of file-input:”     203660406   MASON, DOUGLAS E”
# Example line ofPASSNG file-input:”     203624328   MCCAULEY, MATTHEW J.”
# Example line of file-junk: ” DAYS  TRs with a single “:”.
cat uu_list_C_T_X | sed “s/-*-/:/g” > uu_list_C_T_X_N;
#Edit file to have only the 4 used columns.
cat uu_list_C_T_X_N | awk -F : ‘{print $1$2″:”$3″:”$4″:”$5;}’ > uu_list_C_T_X_N_4C;
#Get the last 4 digits of the SS# in a file.
cat uu_list_C_T_X_N_4C | awk -F : ‘{print $1;}’ | cut -b 6-9 > SSN;
#Generate the user login-name and password.
cat uu_list_C_T_X_N_4C | awk -F : ‘{print $2;}’ | cut -b 0-1 > LIN;
cat uu_list_C_T_X_N_4C | awk -F : ‘{print $3;}’ | cut -b 0-1 > FIN;
cat uu_list_C_T_X_N_4C | awk -F : ‘{print $4;}’ | cut -b 0-1 > SIN;
paste -d :  FIN SIN LIN SSN | sed “s/://g” | tr “[A-Z]” “[a-z]” > LOGNTMP;
cat LOGNTMP | tr “[A-Z]” “[a-z]” > LOGNG;
cat LOGNG | rev > PASSNG;
#Generate formated user names.
cat uu_list_C_T_X_N_4C | awk -F : ‘{print $2;}’ | cut -b 2-12 | tr “[A-Z]” “[a-z]” > LP;
cat uu_list_C_T_X_N_4C | awk -F : ‘{print $3;}’ | cut -b 2-12 | tr “[A-Z]” “[a-z]” > FP;
paste -d “” FIN FP > FNAME;
paste -d “” LIN LP > LNAME;
paste -d ” ” FNAME SIN LNAME > NAME;
#Take out userlist names that already exist, echo errors,
#and add users, set passwords, and set directory permisions.
paste -d “_” LOGNG PASSNG NAME | sed “s/ /+/g”> Raw_ADDLST;
for i in `cat Raw_ADDLST`
do
username=`echo $i | sed “s/_/:/g” | awk -F : ‘{print $1}’`
current_user_exists=`grep -c $username “/etc/passwd”`;
if [ "$current_user_exists" = "1" ]
then
echo “User already on system: “$username
else
#Add users and set passwords and permisions…
username=`echo $i | sed “s/_/:/g” | sed “s/+/ /g” | awk -F : ‘{print $1}’`
password=`echo $i | sed “s/_/:/g” | sed “s/+/ /g” | awk -F : ‘{print $2}’`
fullname=`echo $i | sed “s/_/:/g” | sed “s/+/ /g” | awk -F : ‘{print $3}’`
echo $username”—”$fullname
useradd -m -c “$fullname” $username
echo $password | passwd –stdin $username
fi
done
#Clean up buckets of temp files.
rm -f raw_uu_list, uu_list_C, uu_list_C_T, uu_list_C_T_X, uu_list_C_T_X_N;
rm -f uu_list_C_T_X_N_4C, SSN, FIN, LIN, SIN, LOGNTMP, LOGNG, PASSNG, LP, FP;
rm -f FNAME, LNAME, NAME, Raw_ADDLST;

Python – remove the words translation

Posted on by .

#!/usr/bin/env python

#                       Python – CPSC236

#changes
#
#1. send the origional file to p2cc not the file.c
#
#2. change the output file so as to remove the words translation complete when error…
#
#
#
#

from sys import *
import os
import commands
from string import *

Output=”p2c ”
Output=Output + argv[1]
Output=Output + ” > junk 2>good ”

print Output
os.system(Output)

tmpOutStr1=”grep \”Warning:\” junk”
warnings_found_if0, devnull = commands.getstatusoutput(tmpOutStr1)

tmpOutStr2=”grep \”error\” good”
errors_found_if0, devnull = commands.getstatusoutput(tmpOutStr2)

if (warnings_found_if0==0):
print “Their were warnings found: ”
os.system(“cat junk | more”)

print “”

#if (errors_found_if0==0):
#   print “Their were errors found: ”
#   os.system(“cat good | more”)

if (warnings_found_if0!=0):
#Now try p2cc

new_c_file_str=replace(argv[1],”.pas”,”.c”,1)
Output=”p2cc ”
Output=Output + new_c_file_str
Output=Output + ” > junk 2>good ”
print Output
os.system(Output)

tmpOutStr1=”grep \”Warning:\” junk”
warnings_found_if0, devnull = commands.getstatusoutput(tmpOutStr1)

tmpOutStr2=”grep \”errors\” good”
errors_found_if0, devnull = commands.getstatusoutput(tmpOutStr2)

if ((errors_found_if0 != 0) & (warnings_found_if0 != 0)):
print “Created: ”
print new_c_file_str
print “Sent to p2cc”
print “Success!”
print “Your output is in: a.out”
else:
print “Their were errors found: ”
os.system(“cat good | more”)
os.system(“cat junk | more”)