0

I'm trying to convert the following code from a Batch file to a Shell script. I'm having a hard time of it, it feel so much more complicated than putting together a batch file.

Any help would be appreciate:

code below:

@echo off
    echo %PATH%
    

@for /f "delims=[] tokens=2" %%a in ('ping -n 1 google.com') do (
    set "Google_IP=%%a"
)

pause

@for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^|
findstr [') do (
    set "MY_IP=%%a"
)


)


echo Google IP : %Google_IP%
netstat -a
tracert google.com
echo IP of Current Computer : %MY_IP%


pause>nul & exit
Johntr3
  • 1
  • 1
  • 7
    Welcome to StackOverflow! This site focuses on specific programming problems, and does not offer code writing services like "Please write me a program according to this spec" (whether or not the spec is English or Batch). Please either A. post it on a freelancing site instead, or B. write a bash script and ask about any specific problems during that (after appropriate research like [resolve a hostname to an IP address in a Bash script](https://unix.stackexchange.com/questions/20784) and [set a variable to the output of a command in Bash](https://stackoverflow.com/questions/4651437)) – that other guy Jul 09 '20 at 19:43
  • 3
    Rather than present a load of impenetrable Windows BATCH stuff, you might get on better if you said what you are trying to do. It appears to be something to do with pinging something to get your IP address, maybe? – Mark Setchell Jul 09 '20 at 20:42

1 Answers1

1

The ugly way

#!/bin/bash

echo "Google IP : $(host -t A google.com | cut -d ' ' -f 4)"
netstat -a
traceroute google.com
echo "IP of Current Computer : $(getent hosts $(hostname -s) | cut -d ' ' -f 1)"

I would go with

#!/bin/bash

host -t A google.com
#netstat -a
#traceroute google.com
getent hosts $(hostname -s)
JGK
  • 3,710
  • 1
  • 21
  • 26