shell-scripting

Bash scripting: parameter substitution problem

Hi there, I'm trying to write a simple bash script but something seems wrong, I'm testing the following on the command line: DATE="2010-09-{10,11}" result=`\ls *ext.$DATE.Z` and results in ls: cannot access *ext.2010-09-{10,11}.Z: No such file or directory but if I execute this: result=`\ls *ext.2010-09-{10,11}.Z` it works flawle...

how to use a nested if and perform correct file checks in unix

Need some shell scripting help, especially with my if-then-else logic. I want to combine both conditions, but not sure if the file checks will work the same? Should I be doing something like a nested if?? My script uses the if statements to do file checks to see if they exist, then do something.. There is probably a better way to do fi...

How to find time in sh scripting

I'm trying to find a way to get date and time separately. For date I can do: date -u +%d/%m/%Y What should I do to find the time in the following format? hh/mm/ss Thanks ...

problems combining files using unix cat and zcat in shell script

I've got a problem with my shell script. I am basically trying to create a new log file from (2) files using unix (zcat, cat) commands FileA = gzipped logfile (.gz) FileB = non-gzipped log file (.log) FileC = new file from FileA:FileB My problem is with FileC. For example: FileA has timestamp data from Aug19-Sept3 FileB has timest...

Shell script : How to cut part of a string

Hello, I have following string â â³ eGalax Inc. USB TouchController id=9 [slave pointer (2)] â â³ eGalax Inc. USB TouchController id=10 [slave pointer (2)] and would like to get the list of id ? How this can be done using sed or something else ? Regards, Levon ...

How to get the contents of a webpage in a shell variable ?

In Linux how can I fetch an URL and get its contents in a variable in shell script? ...

Makefile - Why is the read command not reading the user input???

I have the following code inside a Makefile: # Root Path echo "What is the root directory of your webserver? Eg. ~/Server/htdocs" ; read root_path ; echo $root_path ; if [ ! -d $root_path ] ; then \ echo "Error: Could not find that location!" ; exit 1 ; \ fi However when typing anything (eg. "asd") this is what gets returned: Wha...

Find and replace date/time in string

I have already made a regex which should work, but it doesn't work. echo "FileName.17:09:2010 4.16.PM.720p.mp4" | sed -E 's/\d{2}:\d{2}:\d{4}\ (\d|\d{2})\.(\d{2}|\d)\.((AM)|(PM))//g' Should output: FileName..720p.mp4 But instead outputs the same "FileName.17:09:2010 4.16.PM.720p.mp4". ...

how to move files from one path to another path in unix using shell-script

Hi All, i want to move logs files from one path(source path) to another path(destination path). This source path and destination path is present in one text file. as:: source_path=abc/xyz source_path=pqr/abc desination_path=abcd/mlk so i read this file and stored paths in different variables.i have multiple source path so i s...

How to run a shell script in PHP?

I am trying to trigger the running of a shell script using PHP. Essentially, when a user completes an action on our website programmed in PHP, we want to trigger a shell script which itself calls a Java file. Thanks in advance! ...

Reading from an archive using Bourne Shell

I am trying to use Bourne shell scripting for the first time ever, and I cannot seem to figure out determining how to save text from a file to internal script variables. The file format is as follows: acc.text Jason Bourne 213.4 Alice Deweger 1 Mark Harrington 312 The current script that I have (which might be ENTIRELY incorrect as I...

check if file exists

#!/bin/ksh file_name=/home/file2.sh used_var=`grep "poet" $file_name` I want to check if file2.sh exists and also if used_var has some value or it has nothing. ...

How to check if a shell command executed properly or not?

#!/bin/sh tar=$1 if [ -f $tar ] then tar xvf $tar else exit 1 fi ... <more code> I need a conformation that the tar actually happened successfully, otherwise abort the execution of the script. The tar file extract might not go through because some problems with tar command access issues with $tar Do Linux utilities have s...

Can a child process pass the environment variable back to parent process

Consider the following: $ cat t.sh echo "This is from t.sh" eval "t2.sh" echo "\$FROM_t2=$FROM_t2" $ cat t2.sh echo "This is from t2.sh" export FROM_t2="env_var_from_t2" I want to read the value of "FROM_t2" created by t2.sh into t.sh. Is this possible? ...

UNIX shell: how do you tail up to a searchable expression?

The end of git status looks like this: # Untracked files: # (use "git add <file>..." to include in what will be committed) # # Classes/Default.png # Classes/[email protected] ... Since you might have any number of untracked files, I'm trying to tail from the end of the file to "Untracked files" and save it to a temp file, s...

Shell Script Certification

Hi guys, I'm a UNIX shell script programmer, and I would like to know if there is any certification specific for Shell (bash, korn,etc) programmers. Could you help please? Also how about CX-310-105 exam to take Oracle Solaris Associate, does it have value on the market? Thanks ...

Command to find all files in a directory and concat them for a parameter?

Hi, I'm looking for a command which finds all files in a directory using a specific partern, lets say "*.txt" and create a list of parameters from it in BASH. So if the dir contains: file1.txt file2.txt file3.txt nonsense.c I need the string "file1.txt file2.txt file3.txt" I knew there was a BASH/Unix command for this, but I can't re...

Regarding UNIX Variable Date Format

Hi, I have a date value stored in a unix korn shell variable VALUE="2010_09_23" I want to change it to "23-Sep-2010" and store it in VALUE1. How can i do it? VALUE1="23-Sep-2010" ...

Return and save String variable from shell script to Java

Hello I want to save the value in a variable in this script: #!/bin/sh filename=$1 var= $filename | sed 's/\([A-Z]\)/ \1/g'; return var; (Firstable, I am not sure if it is correct), and after thar, get this value and use it in my Java program, like this: Process s = Runtime.getRuntime().exec("./CreateTitle.sh "+filename); OutputStr...

Check database connectivity using Shell script

I am trying to write a shell script to check database connectivity. Within my script I am using the command sqlplus uid/pwd@database-schemaname to connect to my Oracle database. Now I want to save the output generated by this command (before it drops to SQL prompt) in a temp file and then grep / find the string "Connected to" from t...