Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

7
votes
2answers
6k views

Passing two arguments to a command using pipes

Usually, we only need to pass one argument: echo abc | cat echo abc | cat some_file - echo abc | cat - some_file Is there a way to pass two arguments? Something like {echo abc , echo xyz} | cat ...
1
vote
1answer
1k views

Removing files older then 1 month, but leave files created at the 1st day of the month

I'm trying to remove some archive files from a folder on a CentOS fileserver with a cronjob. The requirements: Remove files of the last month The .tgz-file of the first day of the month should be ...
6
votes
3answers
5k views

how to grep and print the next N lines after the hit?

I would like to grep for an occurrence in a text file, then print the following N lines after each occurrence found. Any ideas?
5
votes
2answers
1k views

Writing shell scripts that will run on any shell (using multiple shebang lines?)

I've just started getting deeper into shell scripting, and I've always just thrown my script in a file, marked it chmod +x and then done /path/to/script.sh and let whatever interpreter is the default ...
3
votes
1answer
368 views

Parse multiple HTML to text and rename as parent Directory

In a directory there are many folders .html inside, I would like all HTML parsed as new .txt with the name of the parent directory. Example1/ Index.html>Example1.txt Example2/ ...
1
vote
2answers
391 views

couldn't execute “mysql”: no such file or directory, using autoexpect

I have the following file: exp.exp #!/usr/bin/expect db_host='localhost' db_name='webui_dev' db_user='root' db_pass='rootpass' new_db_name='db_2011' expect <<EOF log_user 0 spawn mysql -h ...
1
vote
4answers
350 views

How to extract two numbers from two strings and calculate the difference in Bash?

I have a text file which contains (among others) the following lines: {chapter}{{1}Einleitung}{27}{chapter.1} {chapter}{{2}Grundlagen}{35}{chapter.2} How can I get the 2 lines from this text ...
0
votes
1answer
235 views

Problems using EXPECT is a BASH shell script

This is the code (bash script): echo "Pass for router:" read -s pass /usr/bin/expect <<EOD spawn ssh 192.168.10.1 -l root 'opkg list-installed' > list-installed.txt #echo @pass expect ...
0
votes
1answer
103 views

Bash delete file when variable = x

I'm creating a bash script which reboots the system at each reboot it adds a new line to a text file, I then read the text file before each reboot. Once the variable holding the number of lines ...
0
votes
2answers
94 views

Showing a stack of ssh connections in terminal

I had this idea for long time and tried several ways to implement, with no luck. Tried to google many times and always finding not quite what is needed. How to do: $ ssh hostA ...
0
votes
1answer
323 views

Execute a command and put the results into a variable… all in a bash script

I'm working on a bash script that backs up a configuration file before copying over a new file. Here's what my snippet looks like: mv ~/myStuff.conf ~/myStuff.conf.bak cp ~/new/myStuff.conf ...