shell-scripting

how to delete 3 days old files using ftp in a shell script (Solaris OS)

I am working on a script to create files basically replica of some tables and ftp those files to the remote machine.there is one more requirement to delete the 3days old files on the remote machine before dumping these files. I need help in writing the ksh for deleting 3 days old files on a remote machine using ftp ...

What is the general syntax of a Unix shell command?

In particular, why is that sometimes the options to some commands are preceded by a + sign and sometimes by a - sign? for example: sort -f sort -nr sort +4n sort +3nr ...

Unexpected behavior of expr

Hi all, It may sound a bit trivial but it actually is quite frustrating: Can anyone explain me this: [~:user$]expr 3 + 2 6 [~:user$]expr 3 / 2 1 [~:user$]expr 3 * 2 expr: syntax error When the man page for expr precisely specifies that ARG1 * ARG2 is arithmetic product of both. Thanks, ...

rearrange column's elements and display count

Hi , i have text file like this: i am fine how are you what i how are i need an output like below: i : 2 am : 1 fine : 1 how : 2 are : 2 you : 1 what : 1 there can be many repititions of the words: how could i do this using a shell script or an awk? ...

Simple way to convert 00:20:40.28 (hours:minutes:seconds.split seconds) to seconds

Whats an easy way to convert 00:20:40.28 to seconds with a bash script? (Split seconds can be cut out, it’s not essential.) ...

How to change the prompt in putty

Hi when i start putty on a server i get the promp like below: hpbl802!benjaminb:~ [22]> How can i change this prompt to benjamin:~ [22]> ...

Run cronjob as user to change desktop background in Ubuntu

I am trying to run this script which changes my desktops background to a random picture in a directory. It works from the command line, and the cronjob gets run (added output and it gets spit out to a log file), but I can't get it to change my background. Here's my current line (set to run every minute for testing). 01 * * * * username ...

shell script running by sensing a file

Hi, i am working on unix. i want to write a shell script which will check for a file called "temp_file.txt" on windows and then execute some commands. is this possible? how could we connect to the windows and go to a specific directory and check for a file? ...

How to capture screenshots from a video clip 50 minutes into the clip and do it fast?

Ok it seems that whenever I tell ffmpeg to take a screen cap half way though the clip (clip can be as long as 10 hours) it uses 100% of 1 cpu core and takes ages… whereas if I let it do a frame at the start it goes real quick, as if it scans though the video to get to the middle instead of just jumping to it! Here is the code im current...

Linux shell: poll the keyboard button's state

I have a script that is executed periodically in the background. I want to prevent its execution if the Shift key is pressed. The idea is to poll the keyboard's Shift button state, and if it's pressed — terminate the script immediately. Any ideas? X server is allowed to use: I guess it will help. UPD: I'm currently using this stupid ...

On LINUX O.S., how to get the name of files that has been dropped onto shell script to boot JAR with the name of file as a argument to JAR

I have a shell script file to run jar on Linux O.S which contains #!/bin/sh #MyApplication MyApplication_home='/Desktop/MyApplication' chkpath="$MyApplication_home/jre6/bin/java" if [ -e $chkpath ] then export PATH=$MyApplication_home/jre6/bin:${PATH} export CLASSPATH=$MyApplication_home/MyJar.jar:${CLASSPATH} java -Xmx512M -jar MyJar.j...

Ash (shell provided by busybox) tutorial

I found that the busybox's ash syntax is different from the other standard shells (sh, bash, tcsh). Is there any documentation of its syntax or a tutorial for ash ? ...

Bash - How to call a function declared in a parent shell?

I am writing a bash script that calls functions declared in the parent shell, but it doesn't work. For example: $ function myfunc() { echo "Here in myfunc" ; } $ myfunc Here in myfunc $ cat test.sh #! /bin/bash echo "Here in the script" myfunc $ ./test.sh Here in the script ./test.sh: line 4: myfunc: command not found $ myfunc Here ...

On Solaris, what is the difference between cut and gcut?

I recently came across this crazy script bug on one of my Solaris machines. I found that cut on Solaris skips lines from the files that it processes (or at least very large ones - 800 MB in my case). > cut -f 1 test.tsv | wc -l 457030 > gcut -f 1 test.tsv | wc -l 840571 > cut -f 1 test.tsv > temp_cut_1.txt > gcut -f 1 test.tsv > tem...

Windows script to download and print a file ... suggestions?

I've need to get a file from a remote (embedded) system (which I can do either by wget or an ftp command) then print the contents of the file. Once I've retrieved and printed the file I don't want to do it again. It's a simple matter to make the embedded system publish a file that contains a number, or directory listing which the ho...

bash: how _best_ to create a script from another script

What is a generalized way to create a bash script from another script. For instance: $./script1 arg1 arg2 > script2 $./script2 $arg1 arg2 I can think of a few ways like simply echoing the output but I was wondering if there was a better way or a command I didn't know about and a google search wasn't very helpful. Thanks in advance f...

How to evaluate http response codes from bash/shell script?

I have the feeling that I'm missing the obvious, but have not succeeded with man [curl|wget] or google ("http" makes such a bad search term). I'm looking for a quick&dirty fix to one of our webservers that frequently fails, returning status code 500 with an error message. Once this happens, it needs to be restarted. As the root cause se...

Raise exception on shell command failure?

I'm writing some scripts in Ruby, and I need to interface with some non-Ruby code via shell commands. I know there are at least 6 different ways of executing shell commands from Ruby, unfortunately, none of these seem to stop execution when a shell command fails. Basically, I'm looking for something that does the equivalent of: set -o...

Need help with the Awk substitute command

I am trying to open a log file and manipulate lines if required. For example 2010-01-31 00:05:59,400 -0500 | [VHX4077ff8Ze1sTnE-op51V] | [TB-bce11b:-16a2-5ed9f542] | [6C7CA345F63F835CB353FF15BD6C5E052EXX8E7A | 1000107@Superfly | 31933782 | 172.9.8.3 | DEVICE_ID_CREATED] I need to edit column 5 and remove everything before the Superfly...

Get a range of lines from a file give start and end line number

Hi, I need to extract a set number of lines from a file given the start line number and end line number. How could I quickly do this under unix (it's actually Solaris so gnu flavour isn't available). Thx ...