Check shares on linux

Check if a Samba share exists in local network

i’m trying to figure out how to make a script for check if a dir exist in the network and than backup a directory in the network. Unfortunatly the IP of this machine (Windows 7 with samba) is not static and everytime is changing. at the moment what I do for backup my notebook is: in W7 notebook, launch cmq and with ipconfig check the ip of the machine in linux, go in /etc/hosts file and change the IP set for the notebook launch rsnapshot manually or wait for the crontab to do it now what I want to do is a script that does: to check which IP is available in a range of IPs check which one has a specific dir available if both tests are ok, I change the hosts name with the IP and I lanunch the rsnapshot. maybe a smartest way could be to check if the MAC Address is available in the network and which IP is associated to it and launch the rssnapshot after have changed the hosts or the rsnapshots.conf file till now what I did is: for ip in 192.168.1.<128..142>; do # for loop and the <> operator

ping -c 1 -t 1 $ip > /dev/null 2> /dev/null # ping and discard output if [ $? -eq 0 ]; then # check the exit code if [check if dir exists for ip $ip] #not sure how do this check /usr/bin/rsnapshot daily else echo "$ is down" fi 

1 Answer 1

Use smbclient to list (-L) the shares ex. :

smbclient -L SERVERNAME | grep -i "YOURSHARENAME" 

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

List of all shared folders

Under this path ( /var/lib/samba/usershares ) only some of my shared folders are available. In other machine there is other folders shown under my machine such as: My Printers, print$ and IPC$ which are not listed in the pass in your answer!

Use this command: smbclient -L localhost . A sample of its output is as follow:

Enter username's password: Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.6-Ubuntu] Sharename Type Comment --------- ---- ------- print$ Disk Printer Drivers IPC$ IPC IPC Service (host-name server (Samba, Ubuntu)) hp1320 Printer Hewlett-Packard hp LaserJet 1320 series HP-LaserJet-1200 Printer HP LaserJet 1200 Public Disk Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.6-Ubuntu] Server Comment --------- ------- host-name server (Samba, Ubuntu) Workgroup Master --------- ------- WORKGROUP HOST-NAME 

Are you trying this on the machine that has the share setup? Else change it to the IP address of the server you are trying to read.

Читайте также:  Linux display no protocol specified

@Lokesh I think Tobias’ coment was meant to be addressed to you. I’d also mention that this specific error usually means that nobody is listening on 139 and 445 port (samba should be listening on at least one of them). You can check if it’s true with ss -an | grep -P «\b(139|445)\b» .

GVFS is the virtual filesystem for the Gnome desktop that allows access to shared drives via SMB, FTP, WebDav, and SFTP. Accessed shares are mounted under ~/.gvfs/ , you can see them there as well.

The command above lists all attached external drives, and network shares, e.g.:

$ gvfs-mount -l Drive(0): 1.5 TB Hard Disk [snip] Mount(0): public on fileserver -> smb://fileserver/public/ Type: GDaemonMount Mount(1): SFTP for bert on server.example.com -> sftp://bert@server.example.com/ Type: GDaemonMount Mount(2): WebDAV as bert on server.example.com -> davs://bert@server.example.com/dav Type: GDaemonMount 

If you add the option -i you get even more information.

For samba shares we have a set of utilities that come with the samba suite:

smbtree is a smb browser program in text mode. It is similar to the «Network Neighborhood» found on Windows computers. It prints a tree with all the known domains, the servers in those domains and the shares on the servers. Manpage

This is the result for sudo smbstatus —shares : Service pid machine Connected at (nothing in the list).

If you browse your own machine in the Network section of Nautilus, you should see all the shares.

In Nautilus, the is a «Browse Netwrok» Item in the sidebar. Inside it, there is only one item: «Windows Network» and inside it there is only one item: «WORKGROUP». If I double click WORKGROUP it asks me for user name and password and if I enter my user name and password for my Ubuntu, it does not accept it! Can you help?

Hit Alt + Ctrl + T to open terminal and run the following command:

Читайте также:  L2tp ipsec linux client gui

At least two ways to do this:

1. mount

$ mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=1959288k,nr_inodes=489822,mode=755) . # etc, etc 

With no options, mount will list all mounted file systems. Two options are available:

See man mount for details. An example from my system:

$ mount -l -t cifs //NetgearNAS-3/backup on /mnt/NetgearNAS/backup type cifs (rw,relatime,vers=1.0,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.246,soft,unix,posixpaths,serverino,mapposix,acl,rsize=1048576,wsize=65536,bsize=1048576,echo_interval=60,actimeo=1) //SynologyNAS-1/backups on /mnt/SynologyNAS/backups type cifs (rw,relatime,vers=3.1.1,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.102,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,rsize=4194304,wsize=4194304,bsize=1048576,echo_interval=60,actimeo=1,user=seamus) 

2. findmnt

findmnt will list all mounted filesystems or search for a filesystem. The findmnt command is able to search in /etc/fstab, /etc/mtab or /proc/self/mountinfo. If device or mountpoint is not given, all filesystems are shown.

With no options, findmnt provides a neat listing of all mounted filesystems in tree format:

$ findmnt TARGET SOURCE FSTYPE OPTIONS / /dev/sda1 ext4 rw,relatime,errors=remount-ro ├─/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/kernel/security securityfs securityfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/fs/cgroup tmpfs tmpfs ro,nosuid,nodev,noexec,mode=755 . # etc, etc 

findmnt has an extensive set of filtering and formatting options, making it well-suited for use in scripts where the output must be parsed — see man findmnt for details. In this case, if we wish to restrict the output to shares (as in the smb/cifs/nfs sense), the -t option is handy:

$ findmnt -t cifs,nfs4 TARGET SOURCE FSTYPE OPTIONS /mnt/SynologyNAS/rpi_share SynologyNAS-1:/volume1/rpi_share nfs4 rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,se /mnt/NetgearNAS-3/backup //NetgearNAS-3/backup cifs rw,relatime,vers=1.0,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.16 /mnt/SynologyNAS/backups //SynologyNAS-1/backups cifs rw,relatime,vers=3.1.1,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168. 

Источник

List samba shares and current users

Looking for a simple way to do this from the command line. List samba shares and the users who can access each of them. List samba shares and the users currently connected to them. List samba shares and every connection (log, including user) that has been established to each of them. Any ideas? Anything you use that’s currently available that will give me the bits I need to put this together? Cheers!

We can list shares from command line using smbtree. We can parse: /etc/samba/smb.conf /var/lib/samba/usershares/*.conf

9 Answers 9

Try smbclient -L ip_of_net_interface -U your_user_name . This option allows you to look at what services are available on a server. You use it as smbclient -L host and a list should appear.

Try to use smbstatus , it seems to be what you need.

smbstatus only lists the current connections. What about listing all shares and users who can access them (even if not connected at the time)?

Will retrieve what’s being shared and which machine (if any) is connected to what.

Perfect! But it only shows if im browsing the share, but not if I just have it mapped to Windows. Where NFS shows constantly, but I guess thats because NFS is constantly «mounted», Windows is just mapped, and not mounted till accessed.

Читайте также:  Transferring files ssh linux

Try net usershare info —long .

/usr/bin/net -> /etc/alternatives/net /etc/alternatives/net -> /usr/bin/net.samba3 
$ man net net - Tool for administration of Samba and remote CIFS servers. 

Best answer — it’s been a very long time since I worked with samba and didn’t know about the net command

Also, on most systems, typing testparm will give you info about the samba shares of the machine you’re currently using. After you press enter at the prompt it’ll also show you every uncommented line of smb.conf which can be useful.

No, testparm only checks for correctness of the configuration file, it shows nothing about what you are currently using.

Where -L is to list users & -v is to be verbose.

Getting the users

Getting the shares per user

Less verbose than smbclient -L is net rpc share list -U $USERNAME

You’ll need both because the list of visible shares differs per user.

While smbstatus —shares list active connections in your computer, you may want to know which folders are selected as samba shared, even when no current connection is active.

Go into this directory and you will get the name of such folders:

I am sharing the list of command that everyone need if you are using smb, I hope this will help you all. if need any help for the same, please comment, I will try to help you to have solution for your problems.

you can write sudo smbstatus command to see the logs shared folder and status of that as well

Samba version 4.7.6-Ubuntu PID Username Group Machine Protocol Version Encryption Signing ---------------------------------------------------------------------------------------------------------------------------------------- 

you can write the command sudo smbtree to get the tree of root folder and subfolders

WORKGROUP \\SSHEEL-HP ssheel-HP server (Samba, Ubuntu) \\SSHEEL-HP\Screenshots \\SSHEEL-HP\Movie \\SSHEEL-HP\IPC$ IPC Service (ssheel-HP server (Samba, Ubuntu)) \\SSHEEL-HP\sambashare Network Shared Folder by Samba Server on Ubuntu \\SSHEEL-HP\print$ Printer Drivers 

you can also type sudo smbcontrol command to get all list of controls that you can use with suffix of that command

if you are getting problem to login so you can also set password for smb to get access of shared folders sudo smbpasswd -a ssheel

ssheel@ssheel-HP:~/Videos$ sudo smbpasswd -a ssheel New SMB password: Retype new SMB password: Added user ssheel. 

Источник

Оцените статью
Adblock
detector