Sponsored Content
Top Forums Shell Programming and Scripting Call one bash file from another bash file. Post 302999532 by emmfranklin on Thursday 22nd of June 2017 09:03:19 AM
Old 06-22-2017
Call one bash file from another bash file.

hi .. greetings ...i need help in bash programming. i am on linux mint.

i have two .sh files.(netcheck.sh and dlinkreboot.sh).. please note . both bash files are working perfectly well independently... but cant work together. . in short i want one bash file to call the other bash file automatically and then the control should come back to the first bash file.
the first file (netcheck.sh) detects if internet is active or gone offline. (it checks every few seconds. if internet is dead then it should call upon the second bash file.
the second file (dlinkreboot.sh) reboots the router. (rebooting the router brings the internet back online)

either you show me how to do this or

show me how both contents can be added in one single file. i tried copy pasting but it doesnt work.
both bash files have different first line (i guess its called the header)
the first one netcheck.sh has this ... #!/bin/bash

the second one dlinkreboot.sh has this ....#!/usr/bin/expect -f

these two headers dont not seem to like each other.

i dont know much about bash programming but using my rusted c++ skills that i studied 16 years back.
********************************************************************************************
This is the content of the first bash file. .. netcheck.sh to check whether net is active or not .

Code:
#!/bin/bash

downTime=0
lastAccessTime=$(date +"%s")
while [ true ]; do
if ! ping -c1 google.com >& /dev/null; then
    downTime=$(( $(date +"%s") - $lastAccessTime ))
else
    downTime=0
    lastAccessTime=$(date +"%s")
    echo "online"
    sleep 2
    date
fi

if [ $downTime -ge 10 ]; then
   echo "no internet"
   sleep 2
   echo "trying to reset modem"

/bin/bash dlinkreboot.sh

fi
done

********************************************************************************

the second bash dlinkreboot.sh is this

Code:
#!/usr/bin/expect -f
 
set timeout 20
 
# router user name and password are identical
set name "admin"
 
# router exit
set name "reboot"
 
# router IP address
set routerip "192.168.254.1"
 
# Read command as arg to this script
#set routercmd [lindex $argv 0]
 
# start telnet
spawn telnet $routerip
sleep 1
 
# send username as admin
expect "Login:"
send -- "admin\r"
sleep 1
# send password as admin
expect "Password:"
send -- "admin\r\r"

# send reboot command
sleep 1

expect *>*
send -- "\r"
expect *>*
send -- "reboot\r"
expect *>*
send -- "\r"
expect *>*
send -- "logout\r"
sleep 70
exit

******************************************************************

Last edited by rbatte1; 06-22-2017 at 12:45 PM.. Reason: Changed ICODE tags to CODE tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: how to call function having it's name in variable?

Hello. Looking for a method of modularizing my bash script, I am stuck with such a problem. For example, I have: MODULE_NAME="test" FUNCTION_NAME="run" How do I can a function with name test_run? (4 Replies)
Discussion started by: FractalizeR
4 Replies

2. Shell Programming and Scripting

Bash copy file contents into an existing file at a specific location

Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ... (6 Replies)
Discussion started by: gshepherd7
6 Replies

3. Shell Programming and Scripting

how to call a bash script using perl

Hi I m new to perl. I m trying to write a perl script that calls a bash script; does anyone have a script already that they can provide or help me out? Thanks a lot. (2 Replies)
Discussion started by: adnan786
2 Replies

4. Shell Programming and Scripting

[Bash]Attempting to Merge text from one file into another file at the line directly under a word

Hello, This is my first post on the forums. So I want to start by thanking anyone who is kind enough to read this post and offer advise. I hope to be an active contributor now that I've found these forums. I have an issue that I figure would be a good first post.. I have 2 text files... (5 Replies)
Discussion started by: efciem
5 Replies

5. Shell Programming and Scripting

How to call multiple variables in bash !!

Hi all , I have a file with below data , bash#cat file.txt user1 amount1 status1 user2 amount2 status2 user3 amount3 status3 user4 amount4 status4 . . . Now i have a command to be executed with above values like below , ./errorcheck -u user1 -a amount1 -s status1 ... (3 Replies)
Discussion started by: gnanasekar_beem
3 Replies

6. Shell Programming and Scripting

Bash script to send lines of file to new file based on Regex

I have a file that looks like this: cat includes CORP-CRASHTEST-BU e:\crashplan\ CORP-TEST /usr/openv/java /usr/openv/logs /usr/openv/man CORP-LABS_TEST /usr/openv/java /usr/openv/logs /usr/openv/man What I want to do is make three new files with just those selections. So the three... (4 Replies)
Discussion started by: newbie2010
4 Replies

7. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

8. Shell Programming and Scripting

Call vba from bash

I am writing a bash function and am having trouble calling a VBA from within it. The line in bold is the path to the VBA. Thank you :). ngs() { call {C:\Users\cmccabe\Desktop\Sanger\NGS_Sanger.xlsx} cd 'C:' C:/Users/cmccabe/Desktop/Python27/ for file in... (16 Replies)
Discussion started by: cmccabe
16 Replies

9. Shell Programming and Scripting

Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :) ... (4 Replies)
Discussion started by: cmccabe
4 Replies

10. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies
BASHBUG(1)						      General Commands Manual							BASHBUG(1)

NAME
bashbug - report a bug in bash SYNOPSIS
bashbug [--version] [--help] [email-address] DESCRIPTION
bashbug is a shell script to help the user compose and mail bug reports concerning bash in a standard format. bashbug invokes the editor specified by the environment variable EDITOR on a temporary copy of the bug report format outline. The user must fill in the appropriate fields and exit the editor. bashbug then mails the completed report to bug-bash@gnu.org, or email-address. If the report cannot be mailed, it is saved in the file dead.bashbug in the invoking user's home directory. The bug report format outline consists of several sections. The first section provides information about the machine, operating system, the bash version, and the compilation environment. The second section should be filled in with a description of the bug. The third sec- tion should be a description of how to reproduce the bug. The optional fourth section is for a proposed fix. Fixes are encouraged. ENVIRONMENT
bashbug will utilize the following environment variables if they exist: EDITOR Specifies the preferred editor. If EDITOR is not set, bashbug defaults to emacs. HOME Directory in which the failed bug report is saved if the mail fails. TMPDIR Directory in which to create temporary files and directories. SEE ALSO
bash(1) AUTHORS
Brian Fox, Free Software Foundation bfox@gnu.org Chet Ramey, Case Western Reserve University chet@po.cwru.edu GNU Bash-4.0 1998 July 30 BASHBUG(1)
All times are GMT -4. The time now is 10:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy