Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Error when running script involving machine name and local network Post 303044858 by honeyhamlet on Thursday 5th of March 2020 10:57:53 AM
Old 03-05-2020
Error when running script involving machine name and local network

Hi everyone, I'm trying to write a script that takes a machine name as a command line argument and displays a message informing me whether the host is on the local network.

Here's what I have:

Code:
#!/bin/bash
gateway=$(ip route | grep default | cut -d' ' -f3)

if [[ $(ip route get "$1" | grep -q $gateway) ]]; then

echo "$1 is on the local network"

else

echo "$1 is not on the local network"

fi

Whenever I run it with my machine name (ubuntu) I get the following output:

Code:
Error: any valid prefix is expected rather than "ubuntu".
ubuntu is not on the local network

I'm not sure what the error means and why I'm getting it, as well as if the script is even doing what it should be doing. Any advice would be appreciated. Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing shell script on local machine

Hi guys, I need to run and test some shell script. At work, i work on ksh. I don't have any such software/client installed at home and i cannot always connect to work from home. At home i have Windows Vista. Is there a free and reliable software where i can run my ksh script? Please let me... (4 Replies)
Discussion started by: jakSun8
4 Replies

2. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

3. Shell Programming and Scripting

check web server running on local and on remote machine

Hi , How to check whether web server is running from remote machine How to check whether web server is running on web server itself Can any one help me soon (1 Reply)
Discussion started by: satheeshkr_cse
1 Replies

4. Programming

shell scripting problems involving operations with remote machine

Hi, i have been developing a shell script to transfer a set of files from one ubuntu system to another. Task: while executing the script the files ( ls, dir, cat) in the source machine should transfer to destination machine(at /home/mac/mac/bin) While the script is executed once again, It... (0 Replies)
Discussion started by: srijith
0 Replies

5. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

6. UNIX for Advanced & Expert Users

FTP While transfering files to local machine to remote machine

Hi Am using unix Ksh Am getting the problem while transferring zero size files through the script . When i transfer zero size files from local machine to remote machine manually i can able to do it . My question its beause of zero size files am not able to transfer through script ? or its... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

7. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

8. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

9. Shell Programming and Scripting

Help with fetching the data from remote machine from my jumpbox(local machine)

Team, Presently i am running a script from my local box(i.e jumpbox) to all the remote machines.Basically fetching basic queries like pwd,mkdir,touch etc and i am able to successfully fetch it from my local machine.But when i want to check certain database related queries like the dbstat... (20 Replies)
Discussion started by: whizkidash
20 Replies

10. Shell Programming and Scripting

How can I execute local script on remote machine and include arguments?

I have a script in local server cd /home/dell/work/BOP/testdir ./processchk po (here processchk is a script & po is passed as an argument) Now I want to execute this script from remote server ssh $username@$hostname "cd /home/dell/work/BOP/testdir; ./processchk po" But Its getting error... (9 Replies)
Discussion started by: manohar2013
9 Replies
netstat(1)						      General Commands Manual							netstat(1)

NAME
netstat - show network status SYNOPSIS
address-family] [system] address-family] [system [core]] address-family] protocol] [system] address-family] protocol] [system [core]] interface] [interval] [system] interface] [interval] [system [core]] DESCRIPTION
displays statistics for network interfaces and protocols, as well as the contents of various network-related data structures. The output format varies according to the options selected. Some options are ignored or invalid when used in combination with other options. Generally, the command takes one of the three forms shown above: o The first form of the command displays a list of active sockets for each protocol. o The second form displays the contents of one of the other network data structures according to the option selected. o The third form displays configuration information for each network interface. It also displays network traffic data on config- ured network interfaces, optionally updated at each interval, measured in seconds. Options are interpreted as follows: Show the state of all sockets, including passive sockets used by server processes. When is used without any options only active sockets are shown. This option does not show the state of X.25 programmatic access sockets. The option is ignored if the or interval option is specified. Show statistics or address control block for only the specified address-family. The following address families are recognized: for for and for This option with applies to the and options. This option with or applies to the and options. Show multicast information for network interfaces. Only the address family is recognized by this option. This option may be combined with the option to display both kinds of information. The option is ignored if the option is specified. Show the state of network interfaces. Only the interfaces that have been configured with an IP address or the option using the command are shown. The output includes both the primary and logical interfaces. (See ifconfig(1M)). The counts for Ipkts and Opkts fields are for IP packets only. This option is ignored if the option is specified. By default, when the option is not specified, shows the state of interfaces configured with either IPv4 or IPv6 addresses. An exception is when the user has not configured any IPv6 address on any interface, does not display the state of the IPv6 loop- back interface. Show information about the specified interface only. This option applies to the and options. Show the multicast routing tables. When is used with the option, displays multicast routing statistics instead. This option is ignored if the option is specified. Show network addresses as numbers. Normally, interprets addresses and attempts to display them symbolically. This option applies to the and options. Show statistics for the specified protocol. The following protocols are recognized: and Show the routing tables. When is used with the option, also displays the network masks in the route entries. This option is ignored if the or interval option is specified and is invalid if the option is specified. Show statistics for all protocols. When this option is used with the option, displays multicast routing statistics instead. This option is ignored if the or interval option is specified and is invalid if the option is specified. Show additional routing information. When is used with the option, also displays the network masks in the route entries. With SCTP, because there may be multiple addresses involved in a SCTP socket endpoint, the command displays all local and remote addresses of a SCTP socket. Note: SCTP is available only if the optional SCTP bundle is installed. Show the output in wide format. This option displays all the fields in the output with their maximum resolution in a single line. Thus, the output can be worked upon with text-processing tools. This option works only with the option and will be ignored when used with any other option. The system argument allows substitution for the default value On PA-RISC systems only, the core argument allows substitution for the default value If no options are specified, displays the status of only active sockets. The display of active and passive sockets status shows the local and remote addresses, send and receive queue sizes (in bytes), protocol, and the internal state of the protocol. The send and receive queue size displayed is usually zero. These fields are displayed only for backward compatibility purposes. Address formats are in two forms: or if the host portion of a socket address is zero. When known, the host and network addresses are dis- played symbolically by using and respectively (see gethostent(3N) and getnetent(3N)) for IPv4, and for IPv6 (see getaddrinfo(3N)). If a symbolic name for an address is unknown, the address is displayed numerically according to the address family. For more information regarding the Internet "dot format" for IPv4 addresses, refer to inet(3N). For more information regarding the Internet "colon format" for IPv6 addresses, refer to inet6(3N). Unspecified or "wildcard" addresses and ports appear as an asterisk The interface display provides a table of cumulative statistics regarding packets transferred, both inbound and outbound. The network addresses of the interface and the maximum transmission unit (MTU) are also displayed. When the interval argument is specified, displays a running count of statistics related to network interfaces. This display consists of a column for the first interface found during auto- configuration and a column summarizing information for all interfaces. To display a running count of statistics for a specific interface, use the option. The first line of each screen of information contains a summary since the system was last rebooted. Subsequent lines of output show values accumulated over the preceding interval. The routing table display indicates the available routes and their status. Each route consists of a destination host or network, a netmask and a gateway to use in forwarding packets. The field shows whether the route is up whether the route is to a gateway or whether the route is a host or network route (with or without The field shows the mask to be applied to the destination IP address of an IP packet to be forwarded. The result will be compared with the destination address in the route entry. If they are the same, then the route is one of the candidates for routing this IP packet. If there are several candidate routes, then the route with the longest field (contiguous 1's starting from the left-most bit position) will be chosen. (see routing(7).) The field shows the address of the immediate gateway for reaching the destination. It can be the address of the outgoing interface if the destination is on a directly connected network. The field identifies which network interface is used for the route. The field displays the path maximum transmission unit (PMTU). If the route is created with a static PMTU value (see route(1M)), the corre- sponding PMTU value permanently overrides the interface MTU. Otherwise, the PMTU value is the same as the MTU of the network interface used for the route. The field is for IPv6 only. Its format is similar to the CIDR notation in IPv4. The prefix is an integer between 0 and 128 inclusive. It specifies how many of the leftmost contiguous bits of the address comprise the prefix. A host route has a prefix of 128. A default route has a prefix of 0 (see route(1M)). The prefix is also used in selecting a route to forward an IPv6 packet. DEPENDENCIES
X.25 option does not list X.25 programmatic access information. AUTHOR
was developed by HP and the University of California, Berkeley. SEE ALSO
ifconfig(1M), nwmgr(1M), route(1M), inet(3N), inet6(3N), gethostent(3N), getnetent(3N), getaddrinfo(3N), hosts(4), networks(4), proto- cols(4), services(4), route(7P), sctp(7), routing(7). netstat(1)
All times are GMT -4. The time now is 07:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy