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
ZIPARCHIVE.OPEN(3)							 1							ZIPARCHIVE.OPEN(3)

ZipArchive::open - Open a ZIP file archive

SYNOPSIS
mixed ZipArchive::open (string $filename, [int $flags]) DESCRIPTION
Opens a new zip archive for reading, writing or modifying. PARAMETERS
o $filename - The file name of the ZIP archive to open. o $flags - The mode to use to open the archive. o ZipArchive::OVERWRITE o ZipArchive::CREATE o ZipArchive::EXCL o ZipArchive::CHECKCONS RETURN VALUES
o $Error codes - Returns TRUE on success or the error code. o ZipArchive::ER_EXISTS File already exists. o ZipArchive::ER_INCONS Zip archive inconsistent. o ZipArchive::ER_INVAL Invalid argument. o ZipArchive::ER_MEMORY Malloc failure. o ZipArchive::ER_NOENT No such file. o ZipArchive::ER_NOZIP Not a zip archive. o ZipArchive::ER_OPEN Can't open file. o ZipArchive::ER_READ Read error. o ZipArchive::ER_SEEK Seek error. EXAMPLES
Example #1 Open and extract <?php $zip = new ZipArchive; $res = $zip->open('test.zip'); if ($res === TRUE) { echo 'ok'; $zip->extractTo('test'); $zip->close(); } else { echo 'failed, code:' . $res; } ?> Example #2 Create an archive <?php $zip = new ZipArchive; $res = $zip->open('test.zip', ZipArchive::CREATE); if ($res === TRUE) { $zip->addFromString('test.txt', 'file content goes here'); $zip->addFile('data.txt', 'entryname.txt'); $zip->close(); echo 'ok'; } else { echo 'failed'; } ?> PHP Documentation Group ZIPARCHIVE.OPEN(3)
All times are GMT -4. The time now is 06:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy