shell-scripting

Problem executing bash file

HI there! I've run into some problem while learning to combine .sh files and PHP. I've create a file test.sh and in that file I call a PHP file called test.php. If I double click on the .sh file then it runs perfectly but when I try to run it from the terminal I get "command not found". I'm in the exact folder as my .sh file but it won...

Auto SSH and execute script

I have roughly 12 computers that each have the same script on them. This script merely pings all the other machines, and prints out whether the machine is "reachable" or "unreachable". However, it is inefficient to login to each machine manually using ssh to execute this script. Suppose I'm logged into node 1. Is there any way to for m...

Shell Script Sequencing with Rake

Hi All, I am working on a rake utility and want to implement something mentioned below: There are some shell commands in a sequence in my Rake file. What I want is that the sequence should wait for the previous command to finish processing before it moves to the next one. sh "git commit -m \"#{args.commit_message}\"" do |ok, res| # ...

How can I find the location of the tcsh shell script I'm executing?

Say I put an executable tcsh file in /path/to/my_script.csh and my current directory is anywhere, for example I'm in /path So I type to/my_script.csh I want to have a line in my_script.csh that will return "/path/to/my_script.csh" - like ruby's __FILE__ ...

Find folders with specific name and no symlink pointing to them

Hey guys, I'm trying to write a shell script under linux, which lists all folders (recursively) with a certain name and no symlink pointing to it. For example, I have: /home/htdocs/cust1/typo3_src-4.2.11 /home/htdocs/cust2/typo3_src-4.2.12 /home/htdocs/cust3/typo3_src-4.2.12 Now I want to go through all subdirectories of /home/htdoc...

Substring extraction using bash shell scripting and awk

So, I have a file called 'dummy' which contains the string: "There is 100% packet loss at node 1". I also have a small script that I want to use to grab the percentage from this file. The script is below. result=`grep 'packet loss' dummy` | awk '{ first=match($0,"[0-9]+%") last=match($0," packet loss") s=substr($0,fi...

Vim: Pipe selected text to shell cmd and receive output on vim info/command line

I want to pipe the selected text to a shell command and receive the one-line output from this shell command on the vim info/command line? What I'm really trying to do: Pipe the selected text to a pastebin-type shell command and I want to receive the output of the shell cmd (which is the http link to the pastebin). Is this possible? ...

How can I test if line is empty in shell script?

I have a shell script like this: cat file | while read line do # run some commands using $line done Now I need to check if the line contains any non-whitespace character ([\n\t ]), and if not, skip it. How can I do this? ...

How do I use a variable argument number in a bash script?

#!/bin/bash # Script to output the total size of requested filetype recursively # Error out if no file types were provided if [ $# -lt 1 ] then echo "Syntax Error, Please provide at least one type, ex: sizeofTypes {filetype1} {filetype2}" exit 0 fi #set first filetype types="-name *."$1 #loop through additional filetypes and appe...

Loop through a set of HTML files and append text at top and bottom of each file

For instance, I have an HTML file like this : a.htm <body> Hello world! </body> I want : a.htm <html> <LINK href='style.css' rel=stylesheet type='text/css'> <body> Hello world! </body> </html> The code I have so far is : #!/bin/sh for i in `ls *.htm` do @echo off echo ***New top line*** > temp.txt type $i >> temp.txt ...

How to read data from keyboard and store it in a file, shellscript

Hi I have a file try.SPEC. This file contains a word "Version: 1.0.0.1" . Now I want to write a shell script which will read the version number from keyboard and insert in the file. eg- if the user enters the version number as 2.1.1.1 then the file will have Version: 2.1.1.1" instead of "Version: 1.0.0.1". like this i want that i must b...

Bash scripting keyboard input

I am creating a bash script for generating certificates. The openssl command that creates a certificate asks for keyboard input. This is every time the same sequence of keys: seven times [ENTER] followed by two times ['y' + ENTER]. How can I do this programmatically? ...

how to create shell script for logs

Hello everybody, I'm currently watching my log files like this tail -f and every now and then I press up key and hit return so new changes in log print into console, how to make it print itself when change in log file occur? Here is the requirement : START loop 1. Check file.log 2. If file.log has changed print the changes 3. else print...

Check if a program exists in bash

I am trying to check if md5sum or digest exists on solaris and script is used on different machines. Here is the function in sh script which is called from a ksh script getMD5cmd () { PATH="${PATH}:/bin:/usr/bin:/usr/sfw/bin:/usr/local/bin:/usr/sbin/bin" if type -p md5sum;then MD5CMD=`type -p md5sum` elif type -p di...

How do I prepare myself for a summer of working on Python using Linux environment?

Hi, I have used just Windows for programming so far. Now, I have an internship starting in two weeks and I will be using just Linux environment with Python programming language. I've installed Ubuntu on my system but have no exposure to shell scripting. I need some advice on how I can quickly learn to use the Linux terminal quickly. An...

Why does bash loop deploy script only seem to work once?

I have a few simple scripts that are intended to daisy chain together to run a specific script on a set of servers all listed out in a file, one per line. The single server deploy script contains the following: 1 #!/bin/bash 2 3 file=$1 4 host=$2 5 6 scp ${file} ${host}:/tmp/ 7 USER=`whoami` 8 ssh -t -t $USER@${host} ...

How to get number of rows deleted from mysql in shell script

Hi all I can't work out how to get the mysql client to return the number of rows deleted to the shell when running a delete. Does anyone know what option will enable this? Or ways around it? Here's what i'm trying, but i get no output: #!/bin/bash deleted=`mysql mydb -e "delete from mytable where insertedtime < '2010-04-01 00:00:00'"|...

How to write scripts that can run in bash and csh?

I'm not sure if this is even possible, but is there a way to write shell scripts that can be interpreted by both the Bourne shell as well as C shell? I want to avoid simply checking for the shell and running a shell-specific code. If this is possible, are there any guides on how to do it? I have always written my scripts for Bourne shel...

Shell script to import mysql dump file.

Hi all, I'm new to mysql. My requirement is to create a shell script to import a sql dump file into mysql in linux and this script should be called by java program for the restoration to take on a button click. Please advice me on this. Regards, Chandu. ...

bash "map" equivalent: run command on each file

I often have a command that processes one file, and I want to run it on every file in a directory. Is there any built-in way to do this? For example, say I have a program data which outputs an important number about a file: ./data foo 137 ./data bar 42 I want to run it on every file in the directory in some manner like this: map da...