shell-scripting

How to determine which directory a link is pointing to using bash

With Bash scripting, is there a way to determine which directory a link is pointing to, then switch it to another directory based on the result? For example, say I have the two following directories: /var/data/1/ and /var/data/2/ I have a link to one of them, say, data_link and it is currently linked to /var/data/1/ When the script i...

Unix shell script - printing all the variables available in the scope

Is there any way to find out the variables available in the scope of the shell script. the scenario is like this, we are using some third party tools and we can customize the output with creating shell scripts with a particular naming convention. we know that certain parameters are being passed to our custom shell scripts but we want to...

How do I Select Highest Number From Series of <string>_# File Names in Bash Script

I have a directory with files heat1.conf heat2.conf ... heat<n>.conf minimize.conf ... other files.... I want my Bash script to be able to grab the highest number filename (so I can delete and replace it when I find an error condition). What's the best way to accomplish this? Please discuss the speed of your solution and why you thi...

Shell: How to replace something of a text with the saved variable value

I saved a value by shell command: For example: timeoutvalue=`echo "timeout=2.0"` And I have to grep the value of timeout from another text, and replace it with this timeoutvalue. For example, the text is egtest: <host ip="255.255.255.0" name="testhost" description="hostfortest" connection="xmlrpc" timeout=4.0/> I want to grep the v...

What does the $# construct mean in bash?(and in general I suppose)

I see foo() { if [[ $# -lt 1 ]]; then return 0 fi ... } What exactly is it comparing by using $# as it does there? ...

Merits of Bash Script v. Python Script for Shell-Command-Heavy Utility

I need to write a script to do the following: Monitor a queuing system, which is accessible by shell commands. Create directories from templates using a mix of inline text editing, cp/mv, command line scripts, and compiled c++ programs. Check for error conditions. Write files on error conditions. Note: 2D arrays would be mildly usefu...

Creating a shell script to run Java program

Hi I used a shell script to run a Java class. My script contains #!/bin/sh java -jar jobs/job.jar These are my failed attempts to run it. [root@]#sh testapp.sh Unable to access jarfile jobs/job.jar if I just do this at the command line it works fine [root@]#java -jar jobs/job.jar thanks. ...

how to excute shell script on difference machine using java

Hi All, i want java code example for excute shell script on difference machine (from windows OS to Unix).Help me pls. Sorry for my question unclear.i have 2 use case for this question : case 1 : Different Machine case 2 : Different OS (because first machine is windows 2003 server os and remote machine is unix) ...

nohup for child process in unix

If I nohuped a parent process in unix, will the spawned child processes have the same protection as their parent?. Suppose, nohup par-process.sh & and if par-process.sh contains the call to child as, par-child.sh will par-child be nohuped or should I do that explicitly for it? Thanks in advance. ...

How to check if a variable is set with bash?

How do I know if a variable is set in bash? For example, how to check if the user gave the 1st parameter to a function? function a { ?? if $1 is set } ...

running scripts parallely and sequentially unix

I have the following requirement where there are 3 scripts say, a2,a3,a4 Now as per the requirement a2,a3 should be executed parallely and a4 sequentially.(ie., a4 should be executed only after the completion of a2&a3). Now I tried this like, ((((echo 'start a2' `date`; nohup a2; echo 'end a2') >>log) &) (((echo 'start a3'; nohup a3; ...

Find long filenames using GNU find -regex

Hi I'm trying to find all long filenames in a directory using: find . -regex './[^/]\{5,\}.txt' According to the GNU find documentation, -regex uses emacs regex by default. So this should give me all files longer than 5 characters (excluding extension). Unfortunately it does not work. It matches nothing. I've tried various variation...

find -daystart argument explanation

So I understand that a line such as: find /var/log/ -mtime +60 -type f -exec ls -l {} \; Will list all files in /var/log which were modified 60 days or more ago. After reading through the find man page though I noticed: Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather th...

Shell Script That Can Check if it Was Backgrounded at Invocation

Hi All, I have written a script that relies on other server responses (uses wget to pull data), and I want it to always be run in the background unquestionably. I know one solution is to just write a wrapper script that will call my script with an '&' appended, but I want to avoid that clutter. Is there a way for a bash (or zsh) script...

understanding sudoers

I have a unix script which creates a temporary log file, say tempfl.log. When this file is created it has permission rw-r--r--. There is a line chmod 0440 /etc/sudoers tempfl.log 2>&1 But when the script is done the permission changes to r--r--r-- but it should be rw-r--r--. If I change the line to chmod 0644 /etc/sudoers tempfl.lo...

sed + match the first word in line and the second word that begin with abc

How to match all lines that begins with word ADDRESS and the second string start with abc characters. remark - ( I need to combine the sed syntax in my shell script) for example more file ADDRESS abc1a (match) ADDRESS abc1b (match) ADDRESS acb1a (will not match) ADRESS abc (will not match) ADDRESS abc2a (will match) ADDRE...

Running shell script without environment variables in Xcode?

Xcode sets variety of environment variables related build when running shell script. Is there a way to running shell script without setting of those variables? ...

shell script + $? as deafult 1 in the begining

hi dear friends I have the following (part of big ksh script) while [[ $? -ne 0 ]] do print -n "ENTER VALID HOST IP" read IP CHECK_IP $IP # CHECK_IP is afuntion that check if IP is valid and return 0 or 1 done as we see in the while the $? is always equal to 0 so we cant ask for the IP the target of the loop...

Simple queue for youtube-dl in linux shell

youtube-dl is a python script that allows one to download youtube videos. It supports an option for batch downloads: -a FILE, --batch-file=FILE file containing URLs to download ('-' for stdin) I want to setup some sort of queue so I can simply append URLs to a file and have youtube-dl process them. Currently, it does not remove f...

How to count number of non empty lines in a file using sed?

hi all how to find how many lines I have in file by sed (need to ignore spaces and empty lines) for example if I have file with 139 lines (line can include only one character) then sed should return 139 lidia ...