shell-scripting

Unable to untar a file?

I have written a shellscript which tries to pull a tar file from an ftp server and untar it locally. I need to extract specific files from the tar archive. The filename of the tarfile contains a date; I need to be able to select a tar file based on this date. abc_myfile_$date.tar is the format of the file I am pulling from the ftp serve...

Automate scp file transfer using a shell script

Hello, I have some n number of files in a directory on my unix system . Is there a way to write a shellscript that will transfer all those files via scp to a remote system, i specify . Ill specify the password within the script, so that i dont have to enter it for each file. Is there a way to do this ? Thank You ...

linux file size

hi i am using this exec("du -sh -S ".$fileFlv.""); command in php to get size of a file all the things works fine but the problem at my end is i want only the size but it dispalys the size as well as name of the file ...

Shell script input containing asterisk

How do I write a shell script (bash on HPUX) that receives a string as an argument containing an asterisk? e.g. myscript my_db_name "SELECT * FROM table;" The asterisk gets expanded to all the file names in the current directory, also if I assign a variable like this. DB_QUERY="$2" echo $DB_QUERY ...

How to count all the lines of code in a directory recursively?

We've got a PHP application and want to count all the lines of code under a specific directory and its subdirectories. We don't need to ignore comments, as we're just trying to get a rough idea. wc -l *.php That command works great within a given directory, but ignores subdirectories. I was thinking this might work, but it is retur...

Bash script to archive files and then copy new ones.

Need some help with this as my shell scripting skills are somewhat less than l337 :( I need to gzip several files and then copy newer ones over the top from another location. I need to be able to call this script in the following manner from other scripts. exec script.sh $oldfile $newfile Can anyone point me in the right direction? ...

Bash Script - umount a device, but don't fail if it's not mounted?

I'm writing a bash script and I have errexit set, so that the script will die if any command doesn't return a 0 exit code, i.e. if any command doesn't complete successfully. This is to make sure that my bash script is robust. I have to mount some filesystems, copy some files over, the umount it. I'm putting a umount /mnt/temp at the sta...

Korn Shell - Date validation in script

I'm trying to do validation of a date entered as numbers only. (e.g. 09042009 as 09/04/2009) The code now just checks the length of the date. How would I validate not only length of the date entry but also that it is a real date? What would be the syntax for combining tests and regular expression? Code as it exists now: echo "Plea...

Is there a bash shortcut for traversing similar directory structures?

The Korn shell used to have a very useful option to cd for traversing similar directory structures e.g. given the following directorys /home/sweet/dev/projects/trunk/projecta/app/models /home/andy/dev/projects/trunk/projecta/app/models Then if you were in the /home/sweet.... directory then you could change to the equivalent director...

Ctrl-R to search backwards for shell commands in csh

I love this shortcut in borne shell, and want to find out if it is possible to simulate and/or have (perhaps to install an add-on or with a script) it in csh or tsch thanks ...

what are good resources to get the most out of csh or tsch?

I would like to get the most out of working in cch or tcsh shell. I am looking for general tips (post them away), online tips, or book. Thanks ...

Working with csv - SQLite vs join

Hi all! I have an old project in our company that uses shell scripting a lot. Most popular commands are: grep, sed, sort. And it was OK for now. But one of the thing really bothers me. Sometimes we have an input data from other companies that is in csv-like formats. These input file are connected by several IDs like they are just a dump...

using gawk in a shell script

Hi I want to use gawk in a for loop. Something like this: for i in gawk {print $1} | tr '\n' ' ' do something using $i this isn't working of course. Ideas? ...

How do I capture a SQLPlus exit code within a shell script?

I have a korn shell script that is login into sqlplus and executing a script. Within the shell script I would like to capture the status code of the sql statement that was executed. Currently there is an error with sql I'm unable to capture it by checking $?. How would I capture the success or error code from the sql statement and pass...

shell script to read and print a part of a string

Good day members, I have an input file which has rows of numerical digits ( close to 2000 rows ) I want to extract out " the second to the eight digit from the right" of every row of the numeric string into a separate file, with the result separated by a comma as shown. Example: input.txt 00000000000001303275310752 000000000000018273...

Extracting first two characters of a string (Shell Scripting)

Hi all - I'm new to sed and awk - so I'm not really sure which is the most efficient way to go about this. I'm looking to extract the first two letters of a string. I could do it if they were going to be same every time, but I can't seem to figure out how to just say, Take n positions of this string from this larger string x. IE. US...

need to create a shell script or a command in unix which can do the following process(command will be preferred)

at the following path \\ncsusnasent02.na.jnj.com\its_diq_na_win_dev\PowerCenter\infa_shared\WCPIT_BIO_EDW\SrcFiles\DDDMD\DDD.CLI026.WK0933.DDDMR45.001.head I have one file DDD.CLI026.WK0933.DDDMR45.001.head if i open this file i get data as following(in a single line) HEADER0101IMS HEALTHDMD Weekly D DD.CLI026.WK0933.DDDMR4...

in csh and tcsh shell how to view only first n lines of the file?

I tired head +10 and it didn't work. thanks ...

Display only files and folders that are symbolic links in tcsh or bash

Basically I want do the following: ls -l[+someflags] (or by some other means) that will only display files that are symbolic links so the output would look -rw-r--r-- 1 username grp size date-time filename -> somedir -rw-r--r-- 1 username grp size date-time filename2 -> somsdfsdf etc. For example, to show only direct...

Need to implement in unix following thing

there is one variable var=581 we need to copy the value of this variable at following address(location) and value should appear in front of $$DRM45_RowCount \ncsusnasent02.na.jnj.com\its_diq_na_win_dev\PowerCenter\infa_shared\WCPIT_BIO_EDW\PrmFiles\LND\IMS_FILE_to_LND.par when I open this file IMS_FILE_to_LND.par it has data as follow...