Watching samba locks script:

smbstatus -L | head -n 2 | tail -n 1 | nl -v0; smbstatus -L | tail -n -3 | grep . | nl;

# loop the command with "watch"

watch "smbstatus -L | head -n 2 | tail -n 1 | nl -v0; smbstatus -L | tail -n -3 | grep . | nl;"

# loop the command with "while" (useful if you dont want the screen cleared, or if you dont have "watch" command)

while true; echo "----`date`-`date +%s`----"; smbstatus -L | head -n 2 | tail -n 1 | nl -v0; smbstatus -L | tail -n -3 | grep . | nl; sleep 2; done;

smbstatus -L  just lists the headers, but it has an extra empty line at the end, and 3 header lines. We extract the important header line, and we number line it (which tabs it a little bit), and we ask that header line to be numbered at 0 (nl -v0 , asks nl to start numbering at 0). We only print that one header line. After that we repeat the smbstatus -L  command, but we extract everything from below the 3 line to the very bottom. We exclude the empty line with grep . The end result looks like this:

     0  Pid          Uid        DenyMode   Access      R/W        Oplock           SharePath   Name   Time
     1  2619         101        DENY_NONE  0x100081    RDONLY     NONE             /data/Main   Datas1/Realestate01   Mon Jan 11 20:14:38 2016
     2  2619         101        DENY_NONE  0x100081    RDONLY     NONE             /data/Main   Datas1   Mon Jan 11 20:14:38 2016

The end

Leave a Reply

Your email address will not be published. Required fields are marked *