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

learn more… | top users | synonyms (2)

2
votes
3answers
34 views

How to read a text file line by line which is not constant in shell scripting

I need to read a text file line by line and the lines are not constant it may vary.For example $ cat file1.txt syntax error at or near "?" at character 1 syntax error at or near "[" at character 1 ...
2
votes
2answers
29 views

fdupes - delete files after comparing two directories

I'm currently trying to solve an issue using fdupes. I'd like to compare two folders with each other, and afterwards delete all duplicate files within one of these directories. Example: Files are ...
5
votes
3answers
77 views

Creating a Bash script that will execute a program and if it exits without crashing, will run it again

I'd like to know the easiest way of creating a bash script that will run an app in MacOSX (it's a UNIX based system so I assumed this was the right place). wait for the program to exit. If the exit ...
5
votes
2answers
138 views

Is there a way to convert a zip to a tar without extracting it to the filesystem?

Is there a way to convert a zip archive to a tar archive without extracting to a temporary directory first? (and without writing my own implementation of tar or unzip)
1
vote
3answers
3k 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" ...
3
votes
4answers
36 views

reading a list of lines from a file writing output to a utility

I have a file with a list of lines I want to read from another file. I want to output those lines to a utility (grep) that lets me read the entire line and pull information from it. The file with the ...
-2
votes
0answers
14 views

How to apply label in clearcase through unix [on hold]

I'm new to scripting. I came across this, I have to create a label for file while checking out I tried command mklabel but it did not work for me. I think I'm not using it in the right format. I work ...
1
vote
2answers
162 views

How to iterate through multiple file extension without caring about case sensitivity?

I've seen various topics on how to iterate through multiple file extensions but in most case, the list is defined. example: for file in ${arg}/**/*.{txt,h,py} do .... done As can be seen, ...
12
votes
6answers
10k views

How to compare to floating point number in a shell script

I want to compare two floating point numbers in a shell script. The following code is not working: #!/bin/bash min=12.45 val=10.35 if (( $val < $min )) ; then min=$val fi echo $min
8
votes
4answers
301 views

Do you prefer bash scripts or aliases for shortcuts?

I have a ~/bin directory (which is on my PATH) where I store a lot of little 1 or 2 line scripts. Some of them just cd into a directory and run a command on a file, like vim or something. But I also ...
2
votes
1answer
44 views

How to set parameter zero ($0) while executing a script?

I can manipulate positional parameters using shift or set -- while a script is interpreted. How can I change $0?
5
votes
3answers
170 views

How to iterate through a list of files with spaces that is sorted (case insensitive)?

I am doing this in OSX which uses bash but obviously, not all bash conventions are used so hopefully your suggestion is available to me :) I have the following files fun bar1.txt Foo bar2.tXT ...
6
votes
3answers
322 views

How you stop 'wget' after it gets a 404?

If you use brace expansion with wget, you can fetch sequentially-numbered images with ease: $ wget 'http://www.iqandreas.com/sample-images/100-100-color/'{90..110}'.jpg' It fetches the first 10 ...
3
votes
1answer
36 views

How do I use sudo to run multiple commands as another user within a portion of a script?

I'm trying to run the following: if [! -f .owner ]; then creator=$(whoami) sudo -u appuser ksh echo "$creator" >> .owner mkdir test1 test2 test3 exit fi However, the ...
-4
votes
2answers
73 views

“bash: [: : integer expression expected” [on hold]

I want this function to return one random word if there aren't any command-line arguments. I am modifying linuxconfig.org's random-word generator to run even when #$ -ne 1. function random-word { ...
3
votes
1answer
35 views

Triggering Bash Before Killed [on hold]

I just made some kind of service code. Check this out: do_start() { while true do if [[ $(pgrep -fl loopsvn.sh | wc -l) -gt 2 ]]; then echo "Already use by another ...
5
votes
1answer
545 views

Noninteractive script running over ssh is interrupted as apt-get finishes

When I run the following non interactive script on Ubuntu Server 13.04 it's interrupted when lxc-docker package finishes installation. Script : ssh -o StrictHostKeychecking=no -t -t -i $CERT ...
10
votes
4answers
577 views

Recursively create directories for all letters

I want to create a directory in such a way that I need to label the directories from a to z. Inside each of these directories, I need to create sub-directories so that they are labelled as aa, ab etc. ...
2
votes
1answer
23 views

Fetching Remote Windows System Information From Linux Server

I need a script/command that would fetch Windows System Information (Host Name,User Name, Domain, OS Info, Hardware Info, Memory Info, processor Info, etc) by running it on a Linux Server (RHEL 6.5 ...
3
votes
2answers
58 views

transfer a file to remote dir only if doesn't exist without replacing

I'm using CentOS linux. In one line cmd, that returns 0 if success, non-0 if failure, I need: Transfer a file to a remote server. Don't transfer the file if filename exists in remote server ...
-2
votes
0answers
11 views

Watchdog TeamCity Server using a shell script [on hold]

I'm trying to write a script that automatically restarts Team City (a continuous integration tool). So far I have this: RESULT=`netstat -na | grep 8111 | awk '{print $7}' | wc -l` if [ "$RESULT" = 0 ...
-1
votes
1answer
24 views

add groups from external file

I want to write a script which add groups to the system, specified in groups.txt file. content of groups.txt : group01 : computer group02 : electronics group03 : IT . ...
2
votes
6answers
13k views

How to compare two dates in a shell

How to compare two dates in a shell script? For example something like todate=2013-07-18 cond=2013-07-15 if [ $todate -ge $cond ]; then break fi It doesn't work. ...
4
votes
6answers
172 views

Finding the number of time a particular number in a file where range also specified

I have a file with numbers separated by ,(comma). In between it also contains a number range like 300-400. Say for example I have a text file, namely testme.txt which looks like, ...
11
votes
3answers
378 views

Comparing two strings in Bash

I have the following if block in my bash script: if [ ${PACKAGENAME} -eq kakadu-v6_4-00902C ]; then echo "successfully entered if block!!" fi The script execution is not entering my if block even ...
6
votes
2answers
60 views

Passing arguments from a file to a bash script

I' ve got this situation: ./ ./myscript.sh ./arguments.txt ./test.sh Inside myscript.sh, i have to run the file test.sh, passing to it the arguments contained inside arguments.txt. myscript.sh is: ...
2
votes
2answers
54 views

Call the script after disconnecting from server

I have a script I made for work that will call a function that takes an argument. I use the arguments to ssh into our servers. My question is: Is there a way to call the method so that if/when I get ...
6
votes
4answers
985 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
1answer
450 views

Script that unpacks a initrd, allows editing of the preseed.cfg and the packs it to cpio and gzip again

I want to program a script that allows what is said in the title. So basically I gunzip the initrd, than unpack the cpio, open vi to allow editing, save, pack with cpio, and gzip again, so nothing ...
4
votes
3answers
104 views

Frequency of words in non-English language text: how can I merge singular and plural forms etc.?

I'm sorting French language words in some text files according to frequency with a focus on insight rather than statistical significance. The challenge is about preserving accented characters and ...
2
votes
1answer
63 views

Asteriks in filename as wildcard not working [on hold]

So I have a folder with many files like 20140720.457812.tmp and I try to count how many lines they have, I tried this: #!/bin/bash lines=`more /folder/20140720*.tmp|wc -l` but I get this error: ...
-1
votes
1answer
26 views

if condition failing in cron [on hold]

I have the shell script shown below. It is running fine if I execute normally, but if I schedule it in a crontab, it is failing in "if condition". O.S : Ubuntu 11.04 script: set -x cd ...
2
votes
1answer
474 views

How to strip color codes out of stdout and pipe to file and stdout

I have a program that uses printf with some tput mixed in it and I'd like to pipe the output to stdout as well as a file. I'd prefer to use sed since I don't want any unnecessary dependencies on my ...
5
votes
1answer
53 views

How to continue a script after it reboots the machine?

I'm writing a shell script in bash. At some point in the script, it detects that the machine needs to be rebooted before continuing. It issues: sudo reboot When the machine comes back up, there ...
6
votes
3answers
695 views

How enable safeguards for CPU temperature

My desktop has a nasty habit. When I have several high intensity applications running and my CPU is at maximum usage for a period of time, the core temperature rises and my computer auto-shuts off. ...
0
votes
1answer
21 views

How to complete a script to move selective files and directories in a filesystem to another (dump) path in a different filesystem?

1) There is a filesystem, say FS1, having below files and directories : drwx------ 2 256 Jun 20 05:47 recovery_scripts drwx------ 2 256 Jun 20 05:47 sqllib -rw------- 1 ...
1
vote
1answer
32 views

Formatting an external HDD with Bash script

At my workplace we have an external HDD connected to a NAS device (Synology). There is a backup tasks which runs weekly and fills the external HDD after a while. Unfortunately the Linux-based OS of ...
2
votes
1answer
28 views

What do I need in my script to be able to change ownership of a directory structure that belongs to root to the current user running the bash script?

My bash script has the following section: su root -c chown -R smithb:other /export/home/smithb/workspace/rootownsit/ exit The directory rootownsit and its two sub directories were created and is ...
0
votes
2answers
411 views

“Expect” automation tool output to shell variable

#!/bin/bash # more commands here expect << EOD spawn telnet localhost 9151 expect -exact "Trying 127.0.0.1...\r Connected to localhost.\r Escape character is '^]'.\r" send -- "AUTHENTICATE ...
3
votes
1answer
30 views

Restricted ssh remote execution with arguments

I need to enable remote execution of a shell script on a server, but deny all other access. The script is a toggle that accepts a single parameter (on/off/status). This comes close to answering my ...
0
votes
0answers
41 views

How to find the cpu and memory usage of a single process in linux

This question is similar to this SO. I wanted to find the CPU and memory utilization for a single process so I decided to use the top -p <$PID> as mentioned in the question. Here is my script. ...
6
votes
3answers
1k views

How to tweet using terminal?

I would like to tweet a message using terminal. I tried something like: curl -u 'TwitterUsername':'TwitterPassword' -d status=”Your Message Here” https://twitter.com/statuses/update.xml but seems ...
2
votes
1answer
40 views

How can I get this script file's functions to load without having to source it every time? “command not found” (Bash/scripting basics)

How can I get this script file's functions to load without having to source it every time? I created a file foo with script functions I'd like to run. It's in /usr/bin, which is in the PATH. File ...
0
votes
0answers
20 views

A script to identify whether a file descriptor has gone bad

Problem : I have a server program running which connects to a remote program using TCP sockets. There many of them (say 20). My problem is one of the socket descriptor has gone bad and has recieved ...
1
vote
2answers
734 views

Need to get the latest file with date timestamp for each month

I am just starting with Unix programming and I have a requirement. I have four files which are placed in my landing zone and I need the scheduler to pick up the latest file of that month and year. ...
2
votes
2answers
53 views

How do you construct a grep & command to match a number of patterns depending on how many are provided at runtime?

I have exported some MS Word documents to plain text and use this function to parse the contents of the .txt files in the current directory: mo1 () { for i in *.txt; do echo "File: $i" grep ...
1
vote
2answers
42 views

Copy ssh public key to multiple Linux hosts

I am trying to copy .ssh/id_rsa.pub from our central server to multiple servers. I have the following script which I usually use to push changes to the different servers. #!/bin/bash for ip in ...
2
votes
3answers
125 views

sed + remove the first directory from path

Please advise on how to remove the first directory from a path by sed, (the inverse pf what basename does). For example echo "/mnt/VPfig/Amer/AR4/Celtel/files/COM.txt" | sed ... I should get: ...
1
vote
1answer
14 views

Create bash script for wine cmd script

I have installed FIFA09 through wine & it runs great...however i have to manually go to installation directory each time & open the terminal there. Then have to write in two steps: wine cmd ...
1
vote
2answers
39 views

Tmux Split Panes in the same window

I am new to using tmux in scripting and I am attempting to manipulate it so when I run a script I can have multiple screens attached and split in my Putty session, and also have it color coded and ...