Avoid a long delay when checking for a file in a disconnected shared directory - windows

When checking if a file exists in a shared directory
if exist \\10.0.0.10\disk\file echo yes
I experience a very long delay in case the shared directory is disconnected.
I need a faster way to perform this check.
I have tried several alternatives
pushd \\10.0.0.10\disk
if exist \\10.0.0.10\disk\nul
net use \\10.0.0.10\disk
...
but all of them fail after an unacceptable long delay
is there any faster (say less than 1 sec) way?
Or is there any net configuration parameter that can change this timeout?
Edited for clarification The problem is not to reconnect to a specific shared folder. The question is to recognize without having to wait long delays, if a file in a shared folder exists.
This is a bat file that collects information from many different sources, user defined, and some of them can be (and eventually very often are) files in shared folders. Some users may configure dozens of possible sources, and some of them might not be not available when the bat is run. So, those locations will be ignored. But I dont want it to impact the overall performance of the process.

You could try to check if the server is up first using ping:
ping 10.0.0.10 -n 1 -w 100
Use %ERRORLEVEL% to check the result, 0 for success, 1 for failure.

I suppose that you can change your location, so it's possible that there is also an ip 10.0.0.10 but it's not the correct device.
You can check first the status of the net use output (findstr can also be used here)
net use | awk '/((Not)|(Connected)).*10.0.0.10\\disk:/{print $1}'
If this fails, you need to check if it's possible to reconnect.
A ping -n 1 10.0.0.10 could help, but it doesn't tell if it's the correct device.
You can check then the MAC of 10.0.0.10 against an expected value, but you should do the dummy ping before to get a reliable result from arp.
arp -a 10.0.0.10 | findstr "12-34-56-12-34-56"
and if this is successful then you can reconnect
net use \\10.0.0.1\disk

Related

Verify IP address?

I need to write a script in which I have to verify if an IP destination respond (read from keyboard).
I supposed I have to use ping, but I'm not sure how.
To learn about the ping command, you may execute the command
man ping
or the command
ping --help
After executing the ping command in your script, you will need to process its return value and/or its output, somehow. Honza gave you a few commands that can be what you need, although you may want to do it differently, for several normal reasons.

How to discover where localhost points to?

I have the following link:
http://127.0.0.1:61374/wse/wsexplorer/wsexplorer.jsp?org.eclipse.wst.ws.explorer=0
Now since this starts with 127.0.0.1, my browser is showing me a file that is in my computer. I want to learn where this file is.
To do so, I need to learn which directory 127.0.0.1:61374 points to. So, I ran:
netstat -ano
In the output:
TCP 127.0.0.1:61374 127.0.0.1:63216 ESTABLISHED 7228
Then I ran:
tasklist
In the output:
javaw.exe 7228 Console 1 950.936 K
So a Java program is running behind this port. However, where do I go from here to discover where is the file http://127.0.0.1:61374/wse/wsexplorer/wsexplorer.jsp?org.eclipse.wst.ws.explorer=0 in my computer?
I also tried searching the whole computer for wse but the search did not return any directory named wse. Is this normal?

Verify network identity through unix commands

First some background: I'm using the LaunchD feature in Mac OSX to periodically launch an application I'll call "AppX". Optimally I like to run this application nearly 24/7. But due to issues with memory leakage (that is my best guess), AppX closes periodically. To solve this, I've created and loaded a simple plist file to launch the application every 6 hours. This itself works perfectly and minimizes application downtime. However, AppX itself can be a drain on my battery, and I'd prefer it only launch when I'm at home, connected to my wifi network.
Please be aware that while I have some experience with C++ and Java, I know very little in the way of Unix.
My question: I'd like to use an if statement to check whether the network I'm connected to is my home wifi network. Being the case that it is, the system will execute the command:
open -a AppX
So... How would I implement an if statement to accomplish this? Any help is appreciated.
There's an older SO question that gives part of the answer:
Get wireless SSID through shell script on Mac OS X
As for the if statement, the following should work:
homenet = "MyHomeNetwork"
netname = /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'
if [ "$netname" -eq "$homenet" ]
then
# Do fancy service startup here
else
# This is not my home network
fi

rsync suddenly hanging indefinitely during transfers

For the past few years, I have been using an rsync one-liner to back up important folders on my Mac Mini desktop (OSX 10.9, 2.5 GHz i5, 4 GB RAM) to a FreeNAS box (0.7.2 Sabanda revision 5266, Pentium D 2.66 GHz, 822MiB RAM [reported by the system, I think there's 1 GB in there]). I am running an rsync daemon on the FreeNAS box. Recently, these transfers have been hanging indefinitely. I have done the usual Google-fu and am unable to identify the source of the problem or a solution.
The one-liner is:
rsync -rvOlt --exclude '.DS_Store' \
--exclude '.com.apple.timemachine.supported' \
--delete /Volumes/Storage/Music/Albums/ 192.168.1.100::albums
I have tried enabling -vvv and --progress, but there is no pattern that I can discern between what hangs and what doesn't. Heck, if I retry, the same file might hang at a different point during the transfer or not at all. A dry run (-n) does not always succeed either. The only "success" I've had is implementing a timeout (--timeout=10) and rerunning the command over and over. Eventually, I creep along, but with no guarantee of success and at a pace that is unacceptable. I've reached a point where I have one file that I can't get past.
The Mac Mini is connected to my router via 5 GHz. The FreeNAS box is wired into that same router on a 100 mbit port. When transfers are actually going, rsync --progress reports 2.5-4 MB/s. According to --progress, a hang is literally just that—no data transfer is occurring as far as I can tell.
I need help with both the diagnostics and the solution.
I was having the same problem. Removing -v didn't work for me. My use-case is slightly different in that I'm going from source (EXT4) to ExFAT. The issue for me was that rsync was attempting to preserve device files and permissions, which ExFAT doesn't support. I was using the -hrltDvaP switches. The -D and -a switches seemed to be my problem. The -a switch translates to -rlptgoD (no -H,-A,-X). The -p, -g, and -o switches seemed to be my root cause as rsync was barfing on one or all of those during runtime. Removing -a and specifying -Prltvc switches explicitly is working for me.
bkupcmd="nice -n$nicelevel /usr/bin/rsync -Prltvc --exclude-from=/var/tmp/ignorelist "
I've been running into the same thing again and again and it seems to help if you drop the -v option (which is annoying if you need that output).
Try using --whole-file/-W.
This command disables the rsync delta-transfer algorithm.
That is what worked for us (WSL to OSX)
our full sync flags were -avWPle
(e was because we were using ssh, and that has to be the last flag)
This happened to me when the remote device ran out of space. The error wouldn't show when --verbose option was used; turning that off yielded some STDERR output that explained that the remote device was out of space. When I freed some space, I was able to run rsync again with --verbose and everything went fine.
I am using openSUSE 13.2 Linux, rsync version 3.1.1-2.4.1.x86_64, and I experienced similar problems, doing an rsync between my laptop and an external hard disk, with the destination device definitively having enough free space.
I thought I got an improvement omitting option -v, but after 10 minutes it was hanging again: strace said:
select(5, [], [4], [], {60, 0}) = 0 (Timeout)
And with "iotop" I counld see confirm that the rsync processes did no significant disk IO any more.
Neither removing the -v option nor limiting the bandwidth using --bwlimit fixed the problem.
Just had a similar problem while doing rsync from harddisk to a FAT32 USB drive. rsync froze already in less than a second in my case and did not react at all after that ... left it with CTRL+C.
Found out that the problem was a combination of usage of hardlinks on the harddisk and having FAT32 filesystem on the USB drive, which does not support hardlinks.
Formatting the USB drive with ext4 solved the problem for me.
In my situation rsync was not actually failing.
I have regular server backups which transfers large files over 500GB+ and have --append-verify or --checkusm over ssh parameters specified.
What I have found upon analysis is that once the client side completes it's file checks then the server side checks start. Which means while the server is doing it's checks the client side will appear hanged and frozen - run htop on the server to rsync working away.
This is likely a non issue if rsync is run in deamon mode on the server and using the rsync protocol instead of ssh for transfers.
On related note, this very LONG wait would trigger SSH timeout and a rsync: connection unexpectedly closed (254 bytes received so far) [sender] error message, sollution is to add ClientAliveInterval 120 and ClientAliveCountMax 720 to /etc/ssh/sshd_config.
I've seen this quite often on 3.0.9 on a directory with hardlinks, but it also happened on 3.1.3.
There is a nice analysis in Debian bug 820916: when its internal sockets are congested with errors, rsync could go into a deadlock.
This might have been fixed in a 3.2 release just a few days ago (Jun 2020):
Avoid a hang when an overabundance of messages clogs up all the I/O buffers.
The only good workaround I can think of is, if the problem is not persistent, then put timeout in front of it: timeout rsync <args> <source> <destination>, then retry. If it is persistent for you, you're the lucky one who can debug it :D
It also happens when the user on target machine has not write permissions on target folder.
You can try giving write permission to others target folder:
sudo chmod -R o+w /path/to/target-folder
In my case, it was the IPC (Intrusion Protection Component) in our firewall. It sees all the TCP SYN packets as a flood attack and kills the connection. I left a rsync over NFS session open and turned off the IPC for the servers firewall rule and it starting working again right away.
rsync -ravh /source /destination
When it happened I was not able to kill the rsync session. It locked up the NFS mount and I would have to reboot the client machine to get it to work again. The strange thing is it would copy some files over then all of a sudden stop. It always seemed to stop on the same file. So I was looking for file issues, permission issues, TCP offloading issues, tried removing the -v in the rsync call. If you are having this issue at least in my case it even happened with a simple.
cp -rp /source /destination
So I knew then to start looking at other factors. So if you have any sort of intrusion protection on a firewall or router between the servers you can try turning that off temporarily to see if it solves your issue as well.
Most likely not "your" problem, but I stumbled upon this question when I was researching a similar behavior:
I'm observing "hanging" when the target site has too much io load. e.G. on one of my small business servers, when someone is resyncing his IMAP account and downloading large batchs of data and a backup job runs that writes his data.
In this situation I notice a steep drop in performance for rsync. Noticeable in a high load value in top on the target machine, even though CPU and Mem are fine.
Waiting for the process to finish has helped every time or interrupting and attempting the rsync at a later time again.
I was having the same problem and it was because I was running out of memory during the rsync. Created a swap file and problem solved.
Had rsync hanging issue on Ubuntu 16. None of the options above helped. The problem was in the source drive (external SSD) which suddenly became faulty. I tried several disk checks, but all of them stuck. Ended up rebooting the system and disk suddenly became accessible again.
Holger Ohmacht aka h8ohmh / 8ohmh:
The problem lies in the filesystem buffer / usage of the interworking of harddisk/hw so far as I could investigate.
Temporal solution for local drives (eg. USB3<->HD) : A script which is polling the changing disk space. If no changing free disk space then rsync is stalled and has to be restarted
cmd="rsync -aW --progress --stats --preallocate --super \
<here your source dir> \
<here your dest dir>"
eval "$cmd" &
rm ./ndf.txt
rm ./odf.txt
while [[ 0 == 0 ]]; do
df > ./ndf.txt
cmp ./odf.txt ./ndf.txt
res="$?"
echo "$res"
if [[ $res == 0 ]]; then
echo "###########################################"
ls -al "./ndf.txt"
ls -al "./odf.txt"
killall rsync
eval "$cmd" &
else
cp ./ndf.txt ./odf.txt
fi
sleep 60
done
Change <source dir> etc to your paths!
In my case it is always stalling by usage of rsync's --preallocate option (normally because of better disk performance and rescueing continuous blocks), so as long as the disk and filesystem drivers not reworked there just this solution

User session timeout force logoff

I have been doing a little research on how to make a script using vbs or batch to set a session time limit for users logging onto a specific set of computers linked through Group Policy.
I am not familiar with log off or timed scripts, I can make the simplest batch script to log the current user off a machine. The problem I get to is not being able to set a timed session, or running the log-off script due to the time limit.
I researched setting it through group policy, then came up with the idea of linking a script to a group policy in the start up for users on the certain set of computers.
I found a vbs by googling key phrases but I am not sure exactly how to implement it with the log off script or how to make it begin its count down
echo.
echo Waiting For thirty minutes...
TIMEOUT /T 1800 /NOBREAKS
echo.
echo (logoff)
echo.
pause >nul
The log off script that I was planning on using goes along the lines of:
shutdown -l -f -t 30 -c "Your 30 minute session is over."
But I cant get the comment to display and the 30 second time doesn’t take affect.
Any help would be greatly appreciated. Thank you for reading.
How about somthing like this?
Set oSystems = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each oSystem in oSystems
oSystem.Win32ShutdownTracker 3600,"Logging off...",0,4
Next
I know this question is old but here you go anyway:
have a .vbs file called invis.vbs and place it in the Startup directory of the user you want to be limited.
It should contain the following (replace #username# with the Username):
wscript.exe “C:\Users\#username#\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Start-up\invis.vbs” “C:\SessionLimit.bat”
Now save the below as a batch file called SessionLimit.bat in the C:\ Directory.
It should contain the following:
#echo off
timeout 1800 /nobreak
shutdown /l ;;Replace this comment with /f if you want the log off to be forced without the Do you want to save your work interruption window.

Resources