1
vote
2answers
17 views

How do I break up a file like split to stdout for piping to a command?

I have a large .sql file full of SELECT statements that contain data I want to insert into my SQL Server database. I'm looking for how I could basically take the file's contents, 100 lines at a time, ...
1
vote
1answer
60 views

Best way to determine piped command to shell script?

Given tree /some/directory | print.sh Is there any way for print.sh to know that "tree -f /some/directory" was called, without trying to parse pid processes?
5
votes
2answers
202 views

Get the actions for a command programmatically

Let's take the git example: $ git<TAB><TAB> git git-import-dscs git-shell git-buildpackage git-import-orig git-upload-archive git-dch git-pbuilder ...
2
votes
1answer
31 views

Conditionals for fish shell

I am going through the fish shell tutorial and find that this simple if-else block does not work if grep fish /etc/shells echo Found fish else if grep bash /etc/shells echo ...
7
votes
5answers
315 views

How to extract logs between two time stamps

I want to extract all logs between two timestamps. Some lines may not have the timestamp, but I want those lines also. In short, I want every line that falls under two time stamps. My log structure ...
1
vote
0answers
17 views

Execute commands on TMUX Detach

Is it possible to execute commands on tmux detach? I usually have a rails console and server running in the tmux session, on detach is it possible to automatically end those? Thanks.
0
votes
2answers
34 views

command condition sometimes integer sometimes string

I want to execute this condition while [ $(cat /path_of a file/) -eq 1 ] The condition is only correct if $(cat /path_of a file/) is an integer and not a string ! How can I overcome this ...
2
votes
1answer
110 views

Bash command not found error

Why would the following script give following errors : ./check1.sh: line 10: Hi,: command not found ./check1.sh: line 21: syntax error: unexpected end of file check1.sh: #!/bin/bash subj="host ...
8
votes
2answers
113 views

How do I elevate privileges in the middle of pipeline?

My guess was as follows: echo "Generating some text" | su - -c cat >/output/file But su says: su: must be run from a terminal What would you do?
3
votes
3answers
74 views

Bash, how to let some background processes run but wait for others?

I have (yet) another wait, &, && control flow question.. Say I have a script something like this where I want to do as much work at the same time as possible: # may take some hours ...
0
votes
1answer
60 views

Scripting - Folders with spaces

I'm trying to write a script that's robust enough to work with spaces. Its currently in a for loop, but the problem I'm having is folders with spaces in its name. ASOURCE="Home Photos 2012 ...
8
votes
3answers
1k views

What does $# mean in shell?

What does $# mean in shell? I have code such as if [ $# -eq 0 ] then I want to understand what $# means, but Google search is very bad for searching these kinds of things.
0
votes
2answers
54 views

why is ! character used in shell scripts [duplicate]

I recently encountered a situation where I tried to use ! as a record separator for my string array in shell script. When I used it in my shell script, the script got expanded automatically. An ...
11
votes
4answers
1k views

How Does Linux deal with shell scripts?

For this question, let's consider a bash shell script, though this question must be applicable to all types of shell script. When someone executes a shell script, does Linux load all the script at ...
1
vote
3answers
43 views

Executing bash shell scripts

I am reading an article on executing bash shell scripts. Method 1: Create a directory for your shell scripts and add the directory to the contents of the PATH variable, so that you can execute the ...
-4
votes
3answers
131 views

How to get IP Address using shell script? [duplicate]

Want to get the IP address using Shell script. Without knowing the eth0 or eth1 or eth2 How to get the particular IP address. I am not interest to get localhost address, want to get private IP ...
-4
votes
4answers
86 views

How to add a 3 lines in a file using shell script? [closed]

I have a file, that file contain 10 lines. And now I want to add 3 lines to end of the file using shell script. After add lines, If I run the script again I don't want to add same lines again. ...
-1
votes
1answer
42 views

Remove directory without `rm -r`

How to remove non-empty directory without using rm -r or find -delete ? I think it is related to unlink, perl or inode
3
votes
1answer
64 views

chmod + silent mode + how force exit code 0 in spite of error

Is it possible execute chmod and ignore error from command Example ( remark file.txt not exsist to show the example ) When I type chmod 777 file.txt I get error on the output chmod: cannot ...
1
vote
2answers
56 views

Script always runs two instances

I was just curious, what may be the reason why script run two instances when executed. Whenever I run my script foo.sh, and when I check using: $ ps -ef | grep foo.sh It always returns two ...
0
votes
3answers
72 views

remove new lines

My input is a csv file like this: 10,"Special Projects,bangaram",0,,0 10,"Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation) ", bangaram,0,,0 10,"Complience with ...
-2
votes
2answers
105 views

how to execute a python program in a shell script

I have a python program in that I wrote some python code (disk.py). I executed this program using the command python disk.py in a terminal, it worked. Now I want to execute it using a shell script.
0
votes
1answer
28 views

Capture Error of LS to file [duplicate]

#!/bin/sh if [ $(ls sample01.log | wc -l) = 1 ] then echo "File Found" > lsOutput.log else echo "File Not Found" > lsOutput.log fi But if sample01.log is not already existing my code already ...
1
vote
3answers
134 views

What does “FILENAME=$(echo $INFILE | grep -oE ”[^/]+$“) ” mean?

FILENAME=$(echo /root/Source/code/script.sh | grep -oE "[^/]+$") I know that it would give me the file name from the file path here as script.sh. But can some one please explain me this?
0
votes
1answer
33 views

How to write simple if condition in ash?

I would like to write a small script that would check every once in a while if I have the internet connection. I would like to run it in crontab on my router where I have ash. I am having a hard ...
4
votes
2answers
133 views

Dump process's stdin and stdout

I have two processes, let's say Parent and Child. Parent launches the Child and communicates with it through child's stdin and stdout. Parent <-> Child These processes use text protocol and I ...
-2
votes
1answer
28 views

Implementation Logic [closed]

I have two files,which is something like this: file1 msgid "New" msgstr "" dsvhuvchvdhcvhc msgid "Old" msgstr "hsvhs" kdnvcjdbvj msgid "Bold" msgstr "" file2 dcbjdsbc msgid "New" msgstr "Alas" ...
1
vote
2answers
41 views

Make Trickle get the correct $PATH

Trickle is a bandwidth limiting program. I have the following script for trickle. #!/bin/bash echo $PATH trickle -s -t 3 -u 200 -d 200 "$@" I have a script in ~/bin/ that want to run the script ...
0
votes
1answer
46 views

shell unexpected end of file error

I had the below script working in a linux machine. page="$(curl http://www.google.com/| grep "title")" if [ -z "$page" ]; then echo "Empty page" else echo "Valid page" fi When am running in ...
2
votes
2answers
176 views

Do I need to encapsulate awk variables in quotes in order to sanitize them?

As per an answer on stackoverflow, it's my understanding that encapsulating bash variables in double-quotes is a fairly safe way of sanitizing user input. What about awk variables? For example, if ...
0
votes
1answer
68 views

Can I use an if statement to detect if bash and dash are being run interactively? [duplicate]

After looking around for a while I've found several good pages describing how to check and see if a bash script is running interactively and there seem to be several methods, but one of them that I ...
1
vote
4answers
74 views

How to get started with bash? [closed]

I need a way to be able to run a script that will automate terminal commands, one after another. As I understand it, this is exactly what bash does. (Am I right, even on this count?) Where can I ...
0
votes
1answer
40 views

How I append the data of Multiple files into one file?

I want to append data of approx 500 files into one file and each of these files are located in their respective dirs. Also How i can verify the contents of merged file e.g How i verify that data ...
0
votes
1answer
35 views

How to measure rlogin time?

I need to monitor the time it takes to rlogin from one HP-UX machine to another. So I wrote this: #!/bin/sh result=`rlogin 10.10.10.1 << EOF exit EOF` result2=`{ time $result >/dev/null; } ...
2
votes
1answer
57 views

indirect variable expansion in POSIX as done in bash? [closed]

Is it possible, or is there some elegant hack to do indirect variable expansion in POSIX as can be done in Bash? For context, I'm trying to do the following: for key in ${!map_*} do # do ...
1
vote
1answer
106 views

how to send keyboard signal using a shell script

I have an application in graphical interface that when I run it, it's not opened in full screen mode, but when I use the keyboard shortcut Alt+Ctrl+M , it becomes fullscreen, I want to change the ...
0
votes
1answer
59 views

Unknown syntax in /etc/rc.d/init.d/functions

Looking at the file /etc/rc.d/init.d/functions, I can see the following is declaring a number of variables as local variables. However, why are the variables killlevel and pid_file have an equal sign ...
4
votes
3answers
180 views

Help Shell script to pass variables to rsync

I'm trying to create a simple wrapper shell script for rsync. When I send file names to my script, rsync can never seem to identify the correct location. The file names have spaces in them. I've tried ...
3
votes
2answers
87 views

Expansion of a shell variable and effect of glob and split on it

This post actually contains two separate questions but I think grouping them together will give some more context. I have gone through this question on quotes around variables but I do not quite ...
1
vote
2answers
75 views

Script to su -c into a screen is not working as intended

I'm working on a script that will allow me to load up a screen from a user via sudo and su -c. However, when I use it, it will just show the shell of the user: sudo su -c "script /dev/null; screen -r ...
2
votes
2answers
47 views

Help with 64-bit integers in scripts?

Maybe I'm overthinking this (although I don't think I am)....or maybe there's a neater way of solving my problem ? I have a requirement that if a file is larger than 1GB, it gets split into smaller ...
0
votes
0answers
20 views

Multiply 2 array index variables shell programming [duplicate]

How do i multiply 2 array index variables given the following foo=(1 2) bar=(0.1 0.2) foobar=$((foo[1]*price[1])) # this is wrong echo "$foobar" Current output : 0 Correct/Expected output : 0.4
1
vote
1answer
49 views

How to FILTER the files with filename and then DELETE the OLDEST file from there? [duplicate]

I create and keep the following automated backup files e.g.: fruits_29-12-2013.gz fruits_30-12-2013.gz fruits_31-12-2013.gz sweets_01-12-2013.gz sweets_02-12-2013.gz sweets_03-12-2013.gz .. ...
3
votes
1answer
52 views

Common flag designations and standards for shell scripts and functions

I have been adjusting to using GETOPT and GETOPTS in my shell scripts and custom functions to enable me to use the functions that I create more flexibly. After using a number of UNIX functions I have ...
3
votes
3answers
82 views

Code duplication in a shell script

My bash script (lets call it myscript) takes input either from stdin (pipe), or form a regular file (if filename was provided as an argument) a) someprog | myscript or b) myscript file.txt ...
0
votes
2answers
63 views

Merging two different files with conditions

I have two different files as shown below. Content of a.txt: HDR|1|||||||||| DTL|@||||||||||| TLR||||||||||||| HDR|1|||||||||||| ...
3
votes
5answers
262 views

What are the special characters to print from a script to move the cursor?

I found that by printing \r from a script the cursor moves to the beginning of the line. What character will move the cursor up one line? Where is a list of these special characters? EDIT: Working ...
3
votes
1answer
112 views

CPU is free, yet bash script not utilizing all CPU resources

I ran a simple script to generate a large (10000000 lines) csv file with 6 fields in which some fields changed in each line/row, using a while loop. The machine had all (32) CPUs free, lot of RAM (~31 ...
2
votes
2answers
213 views

Obtain exclusive read/write lock on a file for atomic updates

I want to have a file that is used as a counter. User A will write and increment this number, while User B requests to read the file. Is it possible that User A can lock this file so no one can read ...
0
votes
4answers
108 views

How to check the process along with its arguments in process list?

I have written a script where i need to pass several arguments with the same script, the script is being executed after a certain time using cron. In order to make sure that there are no multiple ...