Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

20
votes
2answers
750 views

Why escape trivial characters in shell script?

I just opened a legacy shell script (written in old ksh88 on Solaris) and found the following repeated all throughout the code: [ -f $myfile ] && \rm -f $myfile The escaping backslash ...
0
votes
1answer
1k views

How to pkill from a script?

How can I write a script that basically just runs pkill -HUP inetd? I want to restart inetd via a script so I can schedule it to run at a particular time. I tried to write it myself, but I'm getting a ...
8
votes
4answers
755 views

What is the easiest way to execute text from tail at the command line?

Sometimes I'm working on a new (ubuntu) box and I type git and am alerted: The program 'git' is currently not installed. You can install it by typing: apt-get install git-core If that happens I ...
2
votes
2answers
575 views

Search and replace with sed

Last week I accidently externalized all my strings of my eclipse project. I need to revert this and my only hope is sed. I tried to create scripts but failed pathetically because I'm new with sed and ...
2
votes
3answers
587 views

Can I list only specific subdirectories?

I have a folder tree structure like arndell \_databases \_daily \_weekly claremont \_databases \_daily \_weekly monte \_databases \_daily \_weekly and I am only after all files inside ...
4
votes
2answers
2k views

How to configure mailx to support Gmail?

How can I set up mailx to send messages to my Gmail account? What I do now is run the command: mail -s "hello kid" mymail@gmail.com It freezes and does nothing. I tried some variations, but all of ...
2
votes
2answers
449 views

Turn a bash and php script into a distributable rpm

I'm semi unix knowledgeable and I want to be able to call down an rpm from my server, run it with something like rpm -i , and have access to the script anywhere. The script is a combination awk and ...
1
vote
3answers
452 views

Accessing bash [internal] brace expansion iteration number/variable

Question: Is it possible to access which number of a bash iteration is currently being processed? Psuedo-Command mv {1..5}.something.{1..5} $x1.$x2.something Note: This is a logical ...
4
votes
4answers
880 views

script for logging all the stats for a particular process

I want to monitor CPU usage, disk read/write usage for a particular process, say ./myprocess. To monitor CPU top command seems to be a nice option and for read and write iotop seems to be a handy ...
2
votes
2answers
214 views

bash script with network request in pure lsb environment

From what I can understand of LSB documentation, neither wget or netcat are standard tools always available in an LSB environment. Is there some other way to make a http request without being ...
3
votes
2answers
2k views

UNIX move file name with sysdate

I want to make a script in Unix in which I have to move a file daily to a specific path. In order to avoid overlapping of the file, I want the file name along with the date. e.g. mv filename ...
-5
votes
3answers
120 views

Script that checks and saves text to file

Can you give example for a script where user is asked to enter name, surname and age. And then check if name and surname contains only letters and age contains only digits? And if the information is ...
9
votes
6answers
849 views

Text Manipulation Across multiple lines

I Have a file that has text like this: AAAA BBBB CCCC DDDD 1234 5678 9012 3456 EEEE 7890 etc... And i want to match up the Alphabetic lines with the Numeric lines so they are like this: ...
0
votes
1answer
333 views

Postgres 9.0 linux command to windows command conversion [closed]

i am working on an application using delphi 7 as the front end and postgres 9.0 as the back end. I have to upload images to the server so i use \lo_import and \lo_export for inserting images on the ...
2
votes
2answers
411 views

Shell script output incorrectly splitting while being passed as an argument to script

Let's say I have the following two shell scripts: #!/bin/sh #This script is named: args.sh echo 1 "\"Two words\"" 3 , and: #!/bin/sh #This script is named: test.sh echo "Argument 1: "$1 echo ...
0
votes
2answers
227 views

How to generate Zipf-like samples, by using scripting language

Is there any scripting language function (like in python or bash) that samples from a zipf-like distribution, for exponent 0<a<=1. PS: I am aware of existence of a numpy function that can ...
5
votes
1answer
11k views

automate gnuplot plotting with bash

I have 6 files which need to be plotted as line graphs with error margins and output them to different png files. The file format is as follows. seconds mean-average min max How would I go about ...
5
votes
2answers
1k views

How to get top 5 most ram intensive applications from Bash?

So I look at avaliable to me servers load and see that some other user has created some really ram intensive app that kills my server hosting abileties. I wonder what is bash command to get top 5 ...
1
vote
1answer
697 views

Alternative for `sleep seconds` that takes system load into account?

So I develop my server app and some client apps for it. After each rebuild I start my server (which tends to load qup all services for something like 2 seconds) and then I start my clients... So his ...
21
votes
6answers
8k views

Can a script be executable but not readable?

Is it possible to execute a script if there is no permission to read it? In root mode, I made a script and I want the other user to execute this script but not read it. I did chmod to forbid read and ...
2
votes
1answer
745 views

How to script a database migration using SSH?

I am trying to create a sync.sh script that coordinates with our less-than-ideal version control for our website. This script will migrate a copy of the live database to our local development ...
3
votes
2answers
2k views

Exit Google Chrome from terminal

Is there a way to cause google-chrome to quit, from the terminal, besides using killall google-chrome? I would like to be able to close it from a script without killing it.
3
votes
2answers
471 views

How does a script/program executes in unix?

I have a doubt about the execution pattern of a unix script. For example a script containing lines: command B function C() { Myscript // Myscript is a script command D } command E and ...
6
votes
3answers
14k views

How to write a bash script, that logs onto an other machine to do stuff?

Is it possible to write a bash script, that would be started from machine A, logs in on a different machine B by ssh (both machines A and B would be Linux-Machines), copys some files on to machine B ...
2
votes
3answers
539 views

dynamic display of a running process?

I am writing a script and acording to that when i run it certain info will be displayed on the output screen. for example say the constant data displayed is: my name is mukesh. i am 27 years old ...
0
votes
2answers
617 views

Bash script error trying to find directory of script itself: unexpected end of file

Borrowing graciously from this StackOverflow answer, I want to find the directory a script is running in so I can load relative paths for it on login: The script is pretty small right now: ...
3
votes
1answer
547 views

passing file as a parameter with sed and loop

Here File1 is the template. File2 is a csv with 200 rows with the columns scriptname ,jobname, templatename, location The templatename is column with in the file2. Is it possible to do it as below. ...
-2
votes
1answer
76 views

How can I list all files in a Linux directory that holds basic commands and shells used by root and other users using a full path? [closed]

I know I'll be using the command ls but I don't know what holds the basic commands and shells used by root and other users using the full path.
4
votes
1answer
377 views

Writing command synopsis in standard man format

I am writing a script and in the usage() function I want to specify the usage. My script uses either option1 or option2 or both. One of them is mandatory. Is there a standard way to write it up?
1
vote
2answers
917 views

To pass a parameter with sed

For my script I have to read the data from a file. For example I have 2 files: one is a text file, the second is a csv file with 10 columns. What I am trying to do is to read the csv and change the ...
10
votes
4answers
5k views

How to define and load your own shell function in zsh

I am having a hard time defining and running my own shell functions in zsh. I followed the instructions on the official documentation and tried with easy example first, but I failed to get it work. ...
1
vote
2answers
756 views

How to change user with authentication inside shell script

It is possible to change the user within a shell script by su - newuser; but what if the newuser needs authentication. How can I provide the password within the shell script? None of the users is ...
0
votes
2answers
682 views

Automated SSH Login [duplicate]

Possible Duplicate: Shell Script for logging into a ssh server Autentification on SSH connection in OneLine How could I make a SSH Login programmatically on a unix server, I don't have ...
5
votes
2answers
262 views

Is it safe to remove a script file from within that script?

Imagine I have a script foo. It should be run once when the user logs in and isn't needed after a successful run. My question: Is it safe to remove the script file from within the script? E.g.: ...
3
votes
1answer
323 views

Shell script doesn't paint last line of stdout to screen without user input

I have a shell script that's happily doing all my backup process and writing progress to stderr and stdout, with one exception — the last line doesn't get written to my terminal (if I call the script ...
2
votes
3answers
3k views

Faster awk script to get the substring / string we wanted

ORDER EVENT .........[] [] ... so many other tags... [Account<25106>=ACCT1] [Destination...] .. so many other tags. I am currently trying to get the account like this. I tried using match in ...
21
votes
3answers
44k views

What characters do I need to escape when using sed in a sh script?

Take the following script: #!/bin/sh sed 's/(127\.0\.1\.1)\s/\1/' [some file] If I try to run this in sh (dash here), it'll fail because of the parentheses, which need to be escaped. But I don't ...
4
votes
1answer
655 views

Best way to swap filenames

I need to swap filenames of two files (file and file_1). I'm using the following code for it. mv file .phfile mv file_1 file mv .phfile file This works but is very buggy, It sometimes even results ...
4
votes
5answers
1k views

Execute string result from shell script as a set of shell commands

I create a string result from my shell script and i want to execute it as a shell command. For example file_a is: user1@gmail.com user2@gmail.com script: awk '{print "mail -s \"welcome\"", $1}' ...
0
votes
1answer
415 views

Shell script to check server state

I am writing a script that would ssh into the VMWare server and check if the VMs are up or not. There's some error in the server=awk "/$i/{print $2}" /home/dharmit/scripts/vmids line. I am getting ...
1
vote
1answer
237 views

Background script run at login interrupted when I run tmux in terminal

In ~/.profile I run a script in the background (redshift for changing the screen temperature at night time). After logging in, I can open a terminal, and run tmux. However, at this point, redshift ...
1
vote
2answers
933 views

The receiving of returns by Nagios from script through NRPE

I am using nagios3 and want to collect some information from nrpe_server. Next script is at nrpe_server: #!/bin/sh #set -x # script for checking disk usage on ZFS # requires min zpool version 13 or ...
3
votes
2answers
3k views

Making an ext3 filesystem image without mkfs.ext3

On ubuntu I'm using the following to create a ext3 filesystem image system.img. dd if=/dev/zero of=./system.img bs=1000000 count=200 mkfs.ext3 ./system.img I'm attempting to do the same on android ...
4
votes
3answers
4k views

How to get subshell's PID in Korn Shell (equivalent of $BASHPID)

In bash you have this handy variable: $BASHPID wich always returns the currently running subshell's PID. How can I get a subshell's PID in ksh? For example see the code below: #!/usr/bin/ksh93 echo ...
3
votes
5answers
619 views

changing pattern of a text file

A text file has contents something like chair table pen desk Now i want it to be changed and stored in a variable say var as below ('chair','chair'),('table','table'),('pen','pen'),('desk','desk') ...
3
votes
2answers
953 views

zsh: excluding files from a pattern

Say I have the following files: |-- bar `-- foo |-- type_A_1 |-- type_A_2 |-- type_B_1 |-- type_B_2 |-- type_B_xx |-- type_B_xx `-- something_else I thought the ...
1
vote
1answer
360 views

Can I get the backup option of cp and mv to work with directories?

--backup[=CONTROL] make a backup of each existing destination file The man page does say that it works on file. It doesn't seem to have any effect on directories. Is there anyway to make this ...
3
votes
2answers
982 views

Keep global variables values piping through functions

I wrote a little bash script using sed on some html pages to extract some urls. To avoid each time grabbing sed results in a variable then read it again I simply made 3 functions and piped together. ...
3
votes
2answers
2k views

Creating a variable with sed in ksh

I'm using Ksh88 on a Solaris 10 machine. If I do the following: foo="one two three" for i in $foo; do echo $i; done The script executes as expected: $ ./script.ksh one two three However if ...
0
votes
1answer
393 views

Shell script executing in the terminal but not from shell script file [duplicate]

Possible Duplicate: How can I make variables “exported” in a bash script stick around? I have a problem with executing script from file. When I type in command line ...