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

learn more… | top users | synonyms (2)

-1
votes
2answers
4k views

Bash -Extract characters from string

Suppose I have the following variable $string = 'cat somecommandhere' Now the output of the above cat command is test="Thanks serverfault" I want to extract the value between the quotes and ...
2
votes
1answer
5k views

error handling in expect?

I am just improving my quetion becasue i have acieved so far upto this: set username [lindex $argv 0] set password [lindex $argv 1] set hostname [lindex $argv 2] if {[llength $argv] == 0} { ...
2
votes
1answer
2k views

Create sub-directories and organize files by date

I have some directories of files copied from my security camera that I would like to organize into sub-directories by file date. So for example; -rwxrwxrwx 0 root root 4935241 Jul 19 2012 ...
2
votes
2answers
581 views

How to pass the output of a script to a command like ls without the output being split?

Suppose I have a script like this: #!/bin/bash printf '%q\n' "b c" Executing the script prints: b\ c on the commandline. Now, being in a directory which contains a file named b c I want to pass ...
1
vote
1answer
295 views

Is there some sort of “no newline at eof” rules for bash scripts?

I have two files, an env file and a run file. When I deploy them to my Ubuntu Server box I get the error: ./start-admin: line 10: syntax error: unexpected end of file If I deploy and then add a ...
2
votes
1answer
119 views

how do i suppress seds unnessary output while using option -e?

why n option is not working here [root@testgfs2 final]# echo a b c | sed -ne 's/[[:blank:]]/"/gp' -ne 's/^/"/pg' -ne 's/$/"/pg' a"b"c "a"b"c "a"b"c" i just need : "a"b"c" actually ...
2
votes
2answers
323 views

changing pattern by removing spaces?

file : hi hello,new york, , ,brazil site ,brazil january,month is feb , , ,indiana jones task: delete all horizontal space (spaces and tab) between any two comas (like , ,) if ...
0
votes
1answer
134 views

Package Installation log creation

I have written a script for installing packages on Linux(Ubuntu). So I want to create a log file for installation of packages for troubleshooting if any problem occur during installation.So please ...
1
vote
1answer
566 views

How to ssh on multiple ipaddress and get the output and error on the local *nix machine?

command="ls -lrt;uname -a;uname -o" for i in 10.38.227.229 10.38.164.103 do ssh auto21@$i "$command 2>&1" >> log #ssh -n auto21@$i "$command" 2> >> log done i am trying ...
7
votes
1answer
2k views

SSH causes while loop to stop

I have finally managed to boil down a problem I have been struggling with for a few weeks. I use SSH with "authorized keys" to run commands remotely. All is fine except when I do it in a while loop. ...
0
votes
1answer
241 views

Moving Same files from different folders using shell script on AIX 5.4

There are two folders named Folder1 and Folder2. Folder1 has files with name:For example S-080001-0-0.xml with its corresponding same files in Folder2 named S-080001-0-0.xml The change in Folder2 is ...
6
votes
2answers
708 views

Find all files with a Python Shebang

I'm trying to run a PEP8 check against a large source tree. The tree is comprised of a mix of files in various languages. The idea is to check all the Python scripts without having to explicitly list ...
2
votes
1answer
305 views

shell variable in awk is not being passed to all the lines but just for the very first line of input?

inputfile:is2.txt 10.39.5.41,A1,B1 10.39.5.41,A2,B2 10.39.5.41,A3,B3 10.39.5.41,A4,B4 10.39.5.41,A5,B5 10.39.5.41,A6,B6 script : #!/bin/bash second_column="OOOOOOO" # OOOOOOO will be added to ...
1
vote
2answers
405 views

reading from a file and changing its pattern into an array?

I have a CSV file containging entries like this : ipaddress,VLAN,VLANid 10.192.168.1,vlan-xyz,3 10.192.168.1,vlan-abc,8 10.192.168.1,vlan-mnp,11 10.192.163.24,vlan-llz,3 10.192.163.24,vlan-bbz,5 ...
1
vote
3answers
5k views

Print given number in reverse order

clear echo "Enter a number" read n sd=0 rev=0 while [ $n -gt 0 ] do sd=$(( $n % 10 )) rev=$(( $rev *\ 10 + $sd )) n=$(( $n / 10 )) done echo "Reverse number of entered digit is $rev" ...
1
vote
1answer
923 views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing ...
1
vote
2answers
201 views

Automation of openldap installation

In my group we often install ldap on new servers. We have two different configurations currently. A mirrored configuration and just a regular standalone configuration. The installation process gets ...
0
votes
1answer
137 views

How to safely enlarge a gzipped file?

I have a gzipped file (around 3Kb), and I want its size to be exactly 4000. To achieve this goal, is it safe to add trailing padding with zeroes? (By safe I mean that the content of the gzipped file ...
1
vote
2answers
554 views

Command/scripts to check the Reverse DNS Lookup time

I am working on a project in which one master communicates with numbers of slaves. For that it has to make connection with hosts in network. But sometimes it hangs. I think that the reason behind is ...
1
vote
3answers
472 views

Reading a directory in shell script

I want to read a numbered directory which is under a path, into a variable in shell script. The paths are something like this: .../releases/R1/... .../releases/R2/... .../releases/R3/... Each time ...
0
votes
1answer
254 views

Solaris 10, Shell Script, Cursor movement [closed]

#include <signal.h> #include <unistd.h> #include <stdio.h> #include <sys/types.h> #include <time.h> void prtime() { time_t rawtime; struct tm * ...
7
votes
4answers
2k views

redirect and log script output

I am trying to tidy up the following snippets, design goals are to log all output from a script, and should not be a wrapper. Less lines are better. I don't care about user inputs (at this stage), ...
0
votes
1answer
252 views

zmodem not working without minicom

I want to upload and download file from and to the target board. I am able to send the file from the target board to PC using zmodem protocol to be specific using command sz -vv -b filename > ...
-2
votes
3answers
489 views

Find files with similar names in a folder using shell script

I have a requirement of selecting xml files from a folder of same ID's. E.g. There are files with name S-000001-0-0.xml S-000001-0-1.xml S-000001-0-2.xml S-000001-0-3.xml S-000001-0-4.xml ...
0
votes
1answer
2k views

How to parse XML to CSV with a shell script?

What is the ideal way to parse an .xml file into a .csv file that I could include with my shell scripts. I know bash cant do it but I'm unsure if I should try in awk or sed. I imagine a language ...
0
votes
2answers
225 views

Shell script parameter substitution

I have seen a line of shell script as follows: local soft_upgrade=${3:-false} What does this mean? I don't know what 3:-false means.
6
votes
2answers
365 views

Why does set -e not work inside () ||

I've run across some scripting like this recently: ( set -e ; do-stuff; do-more-stuff; ) || echo failed This looks fine to me, but it does not work! The set -e does not apply, when you add the ||. ...
7
votes
4answers
10k views

How do I append text to the beginning and end of multiple text files in Bash?

I have a directory full of text files. My goal is to append text to the beginning and end of all of them. The text that goes at the beginning and end is the same for each file. Based on code I got ...
1
vote
2answers
143 views

sed pattern matching with deletion over a line

I want to delete only some spaces(say 4) after the line$#*425 with space I am not able to complete it please suggest echo "line$#*425 with space " | sed 's/ /\1 \2/g' i am thinking of ...
1
vote
1answer
141 views

Copy files excluding x,y,z causing error in shell script

I'm not well versed in shell scripting but I imagine this to be a painfully easy fix but its eluding me. I need to copy the contents of a directory excluding a number of files. I have a command that ...
1
vote
2answers
97 views

how obtain directory files info

I have the need to get information about a specific directory, basically I need to know the correlation between small, medium and big files. I came up with this: for i in K M G; do printf $i du ...
1
vote
2answers
1k views

case + how to implement equal or less or greater in case syntax

My target is to verify a range of number with (only with case + esac), and print the range. So for example: If the number is between 0 and 80, print >=0<=80 If the number is between 81 and 100 ...
1
vote
1answer
1k views

File is readable by everyone, but I can't open the file

I'm fairly new to Unix and I have written a script: SERVER="/usr/local/abc/.../somefile.txt" OPTION="$1" if [ x$OPTION = "xtitle" ] then grep $OPTION $SERVER exit fi As far as I ...
9
votes
5answers
10k views

Binary to hexadecimal and decimal in a shell script

I have a context where I need to convert binary to hexadecimal and decimal and viceversa in a shell script. Can someone suggest me a tool for this?
1
vote
1answer
462 views

Running a script as Grub boot option

I'm assembling some DR stuff for my Linux boxes. One item that would be really handy would be a GRUB option that would run a script to change my boxes from static IPs to dynamic. I know we could do ...
2
votes
1answer
573 views

How to wait for a subprocess used for I/O redirection?

Consider the following snippet of Bash script: exec 3> >(sleep 1; echo "$BASHPID: here") do-something-interesting exec 3>&- wait $! echo "$BASHPID: there" When executed, it produces: ...
-1
votes
3answers
2k views

How to run a shell script with export command in crontab

I have a shell script that exports values of variables when executed. The same values will be used in another script. How to run this script(test.sh) in cron. #!/bin/sh export I="10" echo $I I will ...
1
vote
1answer
252 views

Cannot enter in centOS with any user

I am using cent OS Operating system without GNOME. In the starting, it asks localhost login: Password: It has one user named service under group name service whose password is also service. I ...
2
votes
1answer
280 views

bash scripting add arguments

I have created a script which takes parameters and arguments. I want to insert the --help argument. I already know how to parse normal arguments with -, but I don't know how to parse the -- ones. to ...
2
votes
1answer
2k views

Bash vs ksh pipes

I am stuck with some problems with my scripts in ksh. FWIW the problem which I am unable to overcome is that when I use a structure such as this command | while read VAR1 do many.commands using ...
2
votes
2answers
232 views

How to send text to a command and THEN read from terminal

I'd like to know if it's possible to send some to a command's stdin and then keep reading from the terminal. The problem i'm trying to solve is executing some initialization code every time i open a ...
3
votes
1answer
317 views

Script to turn off laptop keyboard if USB keyboard is present [duplicate]

My laptop keyboard is broke (Esc keeps randomly being pressed, can't fix it), so I've bought a USB keyboard instead. I want to write a script that will run at login which will check if my USB keyboard ...
1
vote
2answers
636 views

Ignore all matches to negated extglob pattern in recursive ls

I would like to recursively list all files in a directory which match a given input pattern using ls. (Oh, and this is in Bash). The only way I can think of to do this using ls is to shopt -s extglob ...
5
votes
4answers
11k views

Text between two tags

I wanna retrieve whatever is between these two tags – <tr> </tr> – from an html doc. Now I don't have any specific html requirements that would warrant for an html parser. I just plain ...
4
votes
3answers
3k views

whiptail or dialog

I am going to create script which will use user input, so I decided to use whiptail, but little bit confuse that which one is portable and will work in ubuntu 10.x and higher and CentOs5.x and higher. ...
1
vote
1answer
93 views

what is diffrence between “$var” and “${var}” [duplicate]

i have seen in many script usage of "$var" and "${var}", so I just want to know diffrence between "$var" and "${var}"
4
votes
2answers
6k views

list all files newer than given timestamp and sort them

I want to list all files (sorted by date) that are newer than timestamp in format 20130207003851 in directory /tmp only. Subdirectories can be omitted. Using SUSE Linux Enterprise Server 11. The ...
3
votes
1answer
546 views

how to start from within my shell-script xterm which starts mplayer and plays the files that are the argument of the script

What I want to do: Start my script with a list of files as arguments. From within my script I want to start xterm that starts mplayer with these files. I tried several things. I call my script like ...
4
votes
2answers
4k views

Iterate over multiple parameters with spaces in bash script

I have a bash script for my RaspberryPi (running Raspbian) that is supposed to take multiple file names as parameter(s) and play one after the other (using omxplayer). The basic structure is this: ...
2
votes
1answer
5k views

How to remove trailing whitespace at the end of the line in given files (more than one)?

I'm sooo fed up with useless spaces in source files that I've even configured vim to show them. The problem is that I'm very often (if not always) have to deal with useless spaces with my mates ...