Sponsored Content
Full Discussion: Menu driven using Ksh
Top Forums UNIX for Advanced & Expert Users Menu driven using Ksh Post 8561 by g-e-n-o on Sunday 14th of October 2001 07:06:18 PM
Old 10-14-2001
something like this script below, it is written for MKS toolkit to be run on windows but it's based on ksh, it's pretty simple, used for uncompress zips and rars, menu based, simple menu though



Code:
#!/bin/ksh

# dir ---------> nombre de directorio
# numzip ------> cantidad de zips que hay en cada directorio
# zipname -----> nombre de cada zip en el directorio
# numrar ------> cantidad de rars que hay en cada directorio
# rarname -----> nombre de cada rar en el directorio
# log  --------> ruta de los logs
# data --------> directorio de software
# identstr ----> las 3 primeras letras de los ficheros, sirve como wild card

export log=e:\/download\/\/log
export data=e:\/download\/\/rips
export ddate=`date +%C%y%m%d`

unzip()
{
for dir in `grep ^ dir.txt`
do	
	cd $dir
	echo "checking for zips in $dir" >> $log\/${ddate}error.txt
	ls *.zip > zip.txt 2>> $log\/${ddate}error.txt
	if [ $? -eq 0 ]
	then
	numzip=`cat zip.txt | wc -l`
	identstr=`head -1 zip.txt | awk '{print substr($1, 1,3)}'`
	pkunzip -od $identstr\*.zip >> $log\/${ddate}uncompress.log
	status=$?
		if [ `ls *.zip | wc -l` -gt $numzip ]
		then
			echo "More zips were extracted in $dir" >> $log\/${ddate}error.txt
		fi
		case $status in
		0) for zipname in `grep ^ zip.txt`
		   do	
			rm $zipname
		   done
		   ;;
		1) echo "Pkunzip exits with error status 1"
		   ;;
		11) echo "CRC Error during zip extraction in $dir, Status 11" >> $log\/${ddate}error.txt
		    ;;
		*) print "Unexpected exit status, error in $dir" >> $log\/${ddate}error.txt
		   ;;
		esac
	fi
	cd $data
done
}

unrar()
{
for dir in `grep ^ dir.txt`
do	
	cd $dir
	echo "checking for rars in $dir" >> $log\/${ddate}error.txt
	ls *.r* > rar.txt 2>> $log\/${ddate}error.txt
	if [ $? -eq 0 ]
	then
	numrar=`cat rar.txt | wc -l`
	identstr=`head -1 rar.txt | awk '{print substr($1, 1,3)}'`
	rar x -z -y $identstr\*.rar >> $log\/${ddate}uncompress.log
	status=$?
		if [ `ls *.r* | wc -l` -gt $numrar ]
		then
			echo "More rars were extracted in $dir" >> $log\/${ddate}error.txt
		fi
		case $status in
		0) for rarname in `grep ^ rar.txt`
		   do	
			rm $rarname
		   done
		   ;;
		3) echo "CRC Error during rar extraction in $dir" >> $log\/${ddate}error.txt
		   ;;
		*) print "Unexpected exit status, error in $dir" >> $log\/${ddate}error.txt
		   ;;
		esac
	fi
	cd $data
done
}

cleanup()
for dir in `grep ^ dir.txt`
do	
	cd $dir
	rm rar.txt zip.txt *.diz 2>> $log\/${ddate}error.txt
	cd $data
done

echo "Please select uncompressing options"
echo "1. unzip only"
echo "2. unrar only"
echo "3. unzip & unrar"
echo "4. unzip, unrar & cleanup"
echo "5. cleanup only\n"

read option

echo "Error Log starting.........................................\n" > $log\/${ddate}error.txt
echo "Process Log starting.........................................\n" > $log\/${ddate}uncompress.log

case $option in
1) unzip
   ;;
2) unrar
   ;;
3) unzip
   unrar
   ;;
4) unzip
   unrar
   cleanup
   ;;
5) cleanup
   ;;
*) print "Please insert options 1 ~ 5"
   ;;
esac

 

10 More Discussions You Might Find Interesting

1. Programming

menu driven ( like pine) on Linux

Hi guys, I am designing the rdbms in C/C++ on linux platform as my project. Can any one help me in designing menu driven screen (like the pine ) which will print on screen as follows 1) create table 2) add table ............. etc with arrow keys for... (2 Replies)
Discussion started by: amit
2 Replies

2. UNIX for Advanced & Expert Users

Menu Driven UNIX Admin

I need to have a script that can do an automated IPL function (how to reboot the box). I think ‘reboot’ would do the trick. However, how would I go about doing it, for example if the user states from a menu script that I would like to reboot now. The problem is when I do the ‘reboot’ command I... (6 Replies)
Discussion started by: ad4m88
6 Replies

3. Homework & Coursework Questions

Menu Driven Shell Script which accepts1 to 5 options

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) Write a Menu Driven Shell Script which accepts1 to 5 options and performs the following actions for... (1 Reply)
Discussion started by: vaghya
1 Replies

4. Shell Programming and Scripting

Menu driven Script needed ..pls help

Hi Guys.. am new to unix scrpiting..I need a Menu need to create using shell scrpting eg: Food items ready paid if i press "f" need to add items for a file food items.. if i press "r" it need to move into ready and remove from food items if i press "p" need to update a filed in... (1 Reply)
Discussion started by: sasdua
1 Replies

5. UNIX for Dummies Questions & Answers

What is a menu or command line option driven script?

i'm confused what this means. i was asked to design a menu or command line option driven script that reads out of a DB and displays info such as read_data.pl -u <user> -e <event> which would print commands run by <user>with the <event> in the db. any suggestions? i've been using... (2 Replies)
Discussion started by: kpddong
2 Replies

6. Shell Programming and Scripting

Help needed in writing a menu driven script

Hi, I was wondering if someone could help me write a shell script in Linux that backsup/restores data to anywhere I choose but it needs to be menu driven? Thanks, I'm new to Linux/Unix but liking it so far...just hoping to get to grips with the scripts! :) (7 Replies)
Discussion started by: Nicole
7 Replies

7. Shell Programming and Scripting

Menu driven script.

I'm a beginner at scripting and have been putting this script together over the past week. It's no where as polish as it could be. Any tips/suggestions on improving this script would be appreciate it. Every week, my team develops WAR files in tomcat on our test environment and moves them to our... (4 Replies)
Discussion started by: bouncer
4 Replies

8. Shell Programming and Scripting

Use of stty vs trap in script-driven login menu

My employers would like me to selectively run one of several different (already-existing) Korn Shell menu-driven scripts out of the user's .profile file, depending on some yet-to-be-specified user critieria. I've never done this kind of thing, but I have the existing scripts (among other... (5 Replies)
Discussion started by: Clovis_Sangrail
5 Replies

9. UNIX for Dummies Questions & Answers

System administration tasks performed from a menu driven interface

I need to write a shell script that allows some system-administration tasks to be preformed automatically from a menu-driven interface. Automate the following tasks: • Copy directory tree • Delete files or directories • Output Information But I don't understand the question. What is a "menu... (2 Replies)
Discussion started by: femchi
2 Replies

10. Shell Programming and Scripting

Using menu driven script

Hi Team , I wrote a shell script for adding and subtracting two numbers am getting error could some one please help to fix it script: echo "Enter 1 to add:" echo "Enter 2 to sub:" echo "Enter 3 for both addition and subtraction :" read ans; case "$ans" in 1)... (4 Replies)
Discussion started by: knz
4 Replies
DDATE(1)						     Emperor Norton Utilities							  DDATE(1)

NAME
ddate - converts Gregorian dates to Discordian dates SYNOPSIS
ddate [+format] [date] DESCRIPTION
ddate prints the date in Discordian date format. If called with no arguments, ddate will get the current system date, convert this to the Discordian date format and print this on the stan- dard output. Alternatively, a Gregorian date may be specified on the command line, in the form of a numerical day, month and year. If a format string is specified, the Discordian date will be printed in a format specified by the string. This mechanism works similarly to the format string mechanism of date(1), only almost completely differently. The fields are: %A Full name of the day of the week (i.e., Sweetmorn) %a Abbreviated name of the day of the week (i.e., SM) %B Full name of the season (i.e., Chaos) %b Abbreviated name of the season (i.e., Chs) %d Ordinal number of day in season (i.e., 23) %e Cardinal number of day in season (i.e., 23rd) %H Name of current Holyday, if any %N Magic code to prevent rest of format from being printed unless today is a Holyday. %n Newline %t Tab %X Number of days remaining until X-Day. (Not valid if the SubGenius options are not compiled in.) %{ %} Used to enclose the part of the string which is to be replaced with the words "St. Tib's Day" if the current day is St. Tib's Day. %. Try it and see. EXAMPLES
% ddate Sweetmorn, Bureaucracy 42, 3161 YOLD % ddate +'Today is %{%A, the %e of %B%}, %Y. %N%nCelebrate %H' Today is Sweetmorn, the 42nd of Bureaucracy, 3161. % ddate +"It's %{%A, the %e of %B%}, %Y. %N%nCelebrate %H" 26 9 1995 It's Prickle-Prickle, the 50th of Bureaucracy, 3161. Celebrate Bureflux % ddate +'Today's %{%A, the %e of %B%}, %Y. %N%nCelebrate %H' 29 2 1996 Today's St. Tib's Day, 3162. BUGS
ddate(1) will produce undefined behaviour if asked to produce the date for St. Tib's day and its format string does not contain the St. Tib's Day delimiters %{ and %}. NOTE
After `X-Day' passed without incident, the Church of the SubGenius declared that it had got the year upside down - X-Day is actually in 8661 AD rather than 1998 AD. Thus, the True X-Day is Cfn 40, 9827. AUTHOR
Original program by Druel the Chaotic aka Jeremy Johnson (mpython@gnu.ai.mit.edu) Major rewrite by Lee H:. O:. Smith, KYTP, aka Andrew Bulhak (acb@dev.null.org) Five tons of flax. DISTRIBUTION POLICY
Public domain. All rites reversed. SEE ALSO
date(1), http://www.subgenius.com/ Malaclypse the Younger, Principia Discordia, Or How I Found Goddess And What I Did To Her When I Found Her 59 Bureaucracy 3161 DDATE(1)
All times are GMT -4. The time now is 09:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy