Sponsored Content
Top Forums Programming Shell script - if statements dont work Post 302987667 by robertkwild on Wednesday 14th of December 2016 04:21:14 AM
Old 12-14-2016
Shell script - archive tar script

hi all,

made a script and thought i would show you guys about it,


Code:
 #!/bin/bash

    echo "is this archive for an audio tar (press 1) or an audio directory (press 2)"
    read method

    case $method in
        1)
            echo "please specify full path to tar file"
            read -e tar

            base=$(basename "$tar")

            echo "please enter ID number ie ID1234"
            read id

            echo "please specify where you want the tar file to be stored"
            read -e dest

            if ! mv "$tar" "$id"_"$base" ; then
                echo "something went wrong with the mv command, please do manually"
                exit
            fi

            if ! rsync -avh "$id"_"$base" "$dest" ; then
                echo "something went wrong with the rsync command, please do manually"
                exit
            fi

            if ! rm -f "$id"_"$base" ; then
                echo "something went wrong with the rm -f command, please do manually"
                exit
            fi
                
            ;;

        2)
            echo "please specify full path to directory you want to be made into a tar"
            read -e dir

            cd $dir
            cd ..

            base=$(basename "$dir")

            echo "please enter ID number ie ID1234"
            read id

            echo "please specify where you want the tar file to be stored"
            read -e dest

            if ! tar -cf "$id"_"$base".tar "$base" ; then
                echo "something went wrong with the tar, please do manually"
                exit
            fi

            if ! rsync -avh "$id"_"$base".tar "$dest" ; then
                echo "something went wrong with the rsync, please do manually"
                exit
            fi

            if ! rm -f "$id"_"$base".tar ; then
                echo "something went wrong with the rm -f command, please do manually"
                exit
            fi

            if ! rm -rf "$dir" ; then
                echo "something went wrong with the rm -rf command, please do manually"
                exit
            fi

            ;;

        *)
            echo "invalid selection, please re-run the script"
            exit

            ;;

    esac

 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

OS X / fsck / apps dont work no control panel

Alright. My neighbor kid brings me his iBook and says nothing works. He decided to move the file system to his likeness and that semed to create the problems. Now he doesn't have access rights to his home. I have run fsck over and over again and I keep getting ** fs modified ** I have also... (0 Replies)
Discussion started by: maxwell
0 Replies

2. Shell Programming and Scripting

Running remote shell script containing sql statements

I have a shell script which resides on three SCO machines containing some simple sqlplus statments. I need to run these scripts remotely. Currently, I am trying to use rsh to do so: rsh hostname myscript args The problem is that the arguments to the sqlplus statements in the remote shell... (4 Replies)
Discussion started by: Madbreaks
4 Replies

3. UNIX for Advanced & Expert Users

why the date format dont work in crontab

Hi I tried to put a cron job which pipes the logfile appended to date +%d but it didnt work . anyone know how to make this happen thanks in advance -prasad (7 Replies)
Discussion started by: p4cldba
7 Replies

4. Shell Programming and Scripting

if [ -z echo foo | egrep -e 'regexp' != '' ] -> dont work

Hallo, I need to test a String (a special ip number-string). So I want to run that: ipadress=172.0.0.0 # for debugging: echo $ipadress | egrep -e '172\.?\.??\.??$' # the test that doesnt work if test -z `echo $ipadress | egrep -e '172\.?\.??\.??$'` != "" then echo "match" else... (1 Reply)
Discussion started by: wiseguy
1 Replies

5. Shell Programming and Scripting

Looping through a shell script with sql statements

Hello members, I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a... (4 Replies)
Discussion started by: novice82
4 Replies

6. Shell Programming and Scripting

Substitution in a file dont work with an Array in filename

Hi. I´ve a script that should substitude the 8th line in a file called xxx.num6. The "xxx" is set by an array filled with this command: j=0 for Par in *.sys ; do Par=`echo $Par | sed 's/\(.*\).sys/\1/'` ; Par2="$Par" ; echo "${Par2}" j=$((j + 1)); done Now i try... (0 Replies)
Discussion started by: Lock3
0 Replies

7. UNIX for Dummies Questions & Answers

keyboard and mouse dont work after sometime from boot in linux.

when i started booting linux ,after sometime both the mouse and the keyboard are getting freeze and wont respond(also the system gets hanged and all the process running dont go forward) ,nothing seem to work. Keeping in mind that it will work after sometime ,i waited for one hour also ,but... (1 Reply)
Discussion started by: sanjay.login
1 Replies

8. Shell Programming and Scripting

Can we use two shebang statements in a single shell script?

Hi, As per my understanding, we can use two shebang statements in a single shell script. Please see below snippet- #!/bin/bash .......## some code A #!/bin/csh .......## some code B exit 0; Here, code A will be executed using bash shell and code B will be executed with c shell. ... (9 Replies)
Discussion started by: tarunmudgal4u
9 Replies

9. Programming

Breakpoints dont work in Codeblocks, code does not build

Hey so I've written a program and it crashes every time I run it. I tried placing breakpoints to see what was going but to my surprise they do not work! I've placed them anywhere and they do not stop the execution of the program. In fact if I add code and hit rebuild it doesn't even build that... (1 Reply)
Discussion started by: Cambria
1 Replies

10. Shell Programming and Scripting

Dont want to mention user id passwd in shell script

Hi, i have one shell script which transfers files from one server to other server through FTP, but i can see login id and password is not mentioned. kindly help to understand the script.then how below script is working if login and password is not mentioned in script #!/bin/sh... (1 Reply)
Discussion started by: ni3b007
1 Replies
tclsh(1)							 Tcl Applications							  tclsh(1)

__________________________________________________________________________________________________________________________________________________

NAME
tclsh - Simple shell containing Tcl interpreter SYNOPSIS
tclsh ?fileName arg arg ...? _________________________________________________________________ DESCRIPTION
Tclsh is a shell-like application that reads Tcl commands from its standard input or from a file and evaluates them. If invoked with no arguments then it runs interactively, reading Tcl commands from standard input and printing command results and error messages to standard output. It runs until the exit command is invoked or until it reaches end-of-file on its standard input. If there exists a file .tclshrc (or tclshrc.tcl on the Windows platforms) in the home directory of the user, tclsh evaluates the file as a Tcl script just before reading the first command from standard input. SCRIPT FILES
If tclsh is invoked with arguments then the first argument is the name of a script file and any additional arguments are made available to the script as variables (see below). Instead of reading commands from standard input tclsh will read Tcl commands from the named file; tclsh will exit when it reaches the end of the file. The end of the file may be marked either by the physical end of the medium, or by the | character, '32' ('u001a', control-Z). If this character is present in the file, the tclsh application will read text up to but not | including the character. An application that requires this character in the file may safely encode it as ``32'', ``x1a'', or | ``u001a''; or may generate it by use of commands such as format or binary. There is no automatic evaluation of .tclshrc when the name of a script file is presented on the tclsh command line, but the script file can always source it if desired. If you create a Tcl script in a file whose first line is #!/usr/local/bin/tclsh then you can invoke the script file directly from your shell if you mark the file as executable. This assumes that tclsh has been installed in the default location in /usr/local/bin; if it's installed somewhere else then you'll have to modify the above line to match. Many UNIX systems do not allow the #! line to exceed about 30 characters in length, so be sure that the tclsh executable can be accessed with a short file name. An even better approach is to start your script files with the following three lines: #!/bin/sh # the next line restarts using tclsh exec tclsh "$0" "$@" This approach has three advantages over the approach in the previous paragraph. First, the location of the tclsh binary doesn't have to be hard-wired into the script: it can be anywhere in your shell search path. Second, it gets around the 30-character file name limit in the previous approach. Third, this approach will work even if tclsh is itself a shell script (this is done on some systems in order to handle multiple architectures or operating systems: the tclsh script selects one of several binaries to run). The three lines cause both sh and tclsh to process the script, but the exec is only executed by sh. sh processes the script first; it treats the second line as a comment and executes the third line. The exec statement cause the shell to stop processing and instead to start up tclsh to reprocess the entire script. When tclsh starts up, it treats all three lines as comments, since the backslash at the end of the second line causes the third line to be treated as part of the comment on the second line. You should note that it is also common practise to install tclsh with its version number as part of the name. This has the advantage of | allowing multiple versions of Tcl to exist on the same system at once, but also the disadvantage of making it harder to write scripts that | start up uniformly across different versions of Tcl. VARIABLES
Tclsh sets the following Tcl variables: argc Contains a count of the number of arg arguments (0 if none), not including the name of the script file. argv Contains a Tcl list whose elements are the arg arguments, in order, or an empty string if there are no arg arguments. argv0 Contains fileName if it was specified. Otherwise, contains the name by which tclsh was invoked. tcl_interactive Contains 1 if tclsh is running interactively (no fileName was specified and standard input is a terminal-like device), 0 otherwise. PROMPTS
When tclsh is invoked interactively it normally prompts for each command with ``% ''. You can change the prompt by setting the variables tcl_prompt1 and tcl_prompt2. If variable tcl_prompt1 exists then it must consist of a Tcl script to output a prompt; instead of out- putting a prompt tclsh will evaluate the script in tcl_prompt1. The variable tcl_prompt2 is used in a similar way when a newline is typed but the current command isn't yet complete; if tcl_prompt2 isn't set then no prompt is output for incomplete commands. STANDARD CHANNELS
See Tcl_StandardChannels for more explanations. SEE ALSO
fconfigure(n), tclvars(n) KEYWORDS
argument, interpreter, prompt, script file, shell Tcl tclsh(1)
All times are GMT -4. The time now is 11:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy