Tagged Questions

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

learn more… | top users | synonyms (2)

1
vote
2answers
654 views

how to detect command interpreter from within a shell script [duplicate]

Possible Duplicate: How to test what shell I am using in a terminal? For example the following script #!/bin/bash issue_interpreter_name would issue: bash
2
votes
1answer
5k views

How to get exact file size and file name?

Right now I am using ls -lt /my/directory (see below) then php parses the output. But inconsistently because the delimiter is space and there might be two or more spaces in between two fields. The ...
11
votes
2answers
22k views

How do I delete the first n lines of an ascii file using shell commands?

I have multiple files that contain ascii text information in the first 5-10 lines, followed by well-tabulated matrix information. In a shell script, I want to remove these first few lines of text so ...
1
vote
3answers
1k views

How do I run a windows executable in linux shell script?

I have an executable program (no source code, just the compiled executable) that was made in windows (.exe extension). It doesn't use any graphics... it simply reads and writes files. I want to be ...
3
votes
2answers
510 views

Insert multiline text into several files via commandline

I want to insert some code into multiple tex files foo*.tex in a directory, one line after \documentclass{.*}. Note that the files have different document classes so the .* is just a symbolic ...
1
vote
1answer
921 views

How to format a curl command for a special task?

There is a search page in a form http://site.com/search.php and it sends a search query via POST request. I want to fetch this request via curl command line tool to inspect a POST request. The HTML ...
15
votes
8answers
2k views

What is the utility of the : command in shell scripting, given that it explicitly does nothing?

In the answer to this question about comments in shell scripting, it is indicated that the : is a null command that explicitly does nothing (but is not to be used for comments). What would be the ...
36
votes
3answers
15k views

Multiline shell script comments - how does this work?

Recently, I stumbled upon a multiline comment type I have never seen before - here is a script example: echo a # : aaa : ddd # echo b This seems to work, hell, even vim syntax-highlights it. What ...
1
vote
1answer
137 views

Load command parameters from upper level file

I've come across an interesting problem that I have not yet been able to solve satisfyingly. Consider a note taking command that takes two arguments: note $project $note That simply files the ...
1
vote
2answers
585 views

Create MySQL database name using variable from date

for the variable dbnya="echo $(date +%Y%m%d%H%M%S)" When running below code, I will get an error (SQL syntax error) mysql -u root -pthepass -e "CREATE DATABASE demo$dbnya CHARACTER SET utf8 ...
1
vote
1answer
936 views

Running shell commands in .sh file results to error

I have two following linux shell commands: echo 'CPU type and model' cat /proc/cpuinfo | head -5 | tail -1 When i run these commands directly in Terminal, i get this result truly: CPU type and ...
19
votes
3answers
846 views

Which are the standard commands available in every Linux based distribution?

I would like to know which are the standard commands available in every Linux system. For example if you get a debian/ubuntu/redhat/suse/arch/slackware etc, you will always find there commands like: ...
3
votes
4answers
355 views

Run a given command on every subpath of a long path

Say I have a long path such as: /a/b/c/d/e/f I would like to run a command only on each of the subpaths of the path: e.g. If my command is cmd, I am looking for a one-liner that can do (perhaps ...
2
votes
1answer
230 views

Is it a good idea to supplement shell script with perl purely for use of regex?

I'm looking for a simple way to utilize regex in a UNIX shell script where not every system will have perl extensions built into grep. What is really helpful about perl regex here is back/forward ...
12
votes
2answers
734 views

When to use a semi-colon between environment variables and a command

Can anyone explain why the semi-colon is necessary in order for the LANG to be seen as updated by bash? Doesn't work: > LANG=Ja_JP bash -c "echo $LANG" en_US Works: > LANG=Ja_JP ; bash -c ...
3
votes
2answers
4k views

Move huge number of files into date structured directory order

I have about 1 million files in this directory: /home/username/images/ Each of the files are called something like: 012345678910(Place)_0_20120414185957_28841.jpg with the timestamp part of the ...
2
votes
3answers
1k views

QEMU do not start when executed in background inside shell script

I have an application that runs fine, with and without '&' when run directly from the terminal. However, if I try to execute it from a shell script, it works only if the trailing '&' is ...
9
votes
3answers
2k views

Substituting strings in a very large file

I have a very long series of urls with no separating character, in the same format as below: http://example.comhttp://example.nethttp://example.orghttp://etc... I want each URL to be on a new line. ...
4
votes
1answer
1k views

How to create a confirmation question in Linux?

I have a certain command (git push server-name) that has major consequences. How to require confirmation for this command only? It should ignore white space. The confirmation could be Enter 'yes i am ...
0
votes
2answers
409 views

Functional shell scripting [closed]

I found out that when I want to create some shell script or advanced command it always made me trouble to remember the names of the commands and their switches. e.g. tr -d '\n' < file | wc -c ...
3
votes
2answers
2k views

sourcing a file inside a script

I'd like to source a file inside a tcsh script. In code: #!/bin/tcsh unsetenv LD_LIBRARY_PATH source $1 echo $LD_LIBRARY_PATH > temp_file The expected result: The environment variable set ...
1
vote
5answers
3k views

Execute a command on multiple hosts, but only print command if it is successful?

Here's what I want to do. I want to check over 100 hosts and see if a file exists on that host. If the file does exist, then I want to print the hostname and the output of the command. In this ...
1
vote
2answers
176 views

Shell script to detect PDFs with non-ASCII contents

I need a shell script to detect valid PDFs. That is, I need to retain only plain ASCII PDFs. Other PDFs which contain non-ASCII contents and malicious scripts need to be deleted. How could I go about ...
0
votes
1answer
192 views

How to use a password as an external variable in shell?

I have this MySQL backup script that I use to back up MySQL databases. Very useful, and it runs on fixed intervals using a cron. However, I need somehow provide this script with the MySQL password. ...
20
votes
2answers
766 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
772 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
593 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
606 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
491 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
466 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
936 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
218 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
892 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
353 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
457 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
249 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 ...
6
votes
1answer
12k 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
2k 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
727 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
9k 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
802 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 ...
4
votes
3answers
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
479 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
567 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
667 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: ...