How to add a disk back to sysfs after deleting it - filesystems

A fs disk failure was simulated by:
echo 1 > /sys/block/sda/device/delete
which removes it from /dev dir. What is the procedure of adding it back?

#/bin/bash
# ReScan all SCSI/SATA Hosts
for SHOST in /sys/class/scsi_host/host*; do
echo -n "Scanning ${SHOST##*/}..."
echo "- - -" > ${SHOST}/scan
echo Done
done
https://serverfault.com/questions/882835/add-a-scsi-disk-on-linux-without-rebooting

I had a similar problem. I removed the disks, which were connected by scsi. Command:
rescan-scsi-bus.sh
helped me get back all deleted drives.

Related

bat file for changing the timestamp of a file

I would like to have a bat file find a specific file within a directory and have it update the time stamp to be current and or synched with the time of activating the bat file.
You don't need to use "touch.exe" to accomplish this. A simple script like this will prove the case:
#echo off
ECHO Test1:
SET FILENAME=test.xml
copy /b %FILENAME% +,,
dir %FILENAME%
timeout 64
ECHO Test2:
copy /b %FILENAME%,,+
dir %FILENAME%
pause
This proves that there are 2 different ways to do this, syntactically.
Can you use touch (already suggested in Jubjub Bandersnatch's comment):
change the modification time from all TXT files to now:
touch -m *.txt
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.
-a change only the access time
-c do not create any files
-d, --date=STRING parse STRING and use it instead of current time
-f (ignored)
-m change only the modification time
-r, --reference=FILE use this file's times instead of current time
-t STAMP use MMDDhhmm[[CC]YY][.ss] instead of current time
--time=WORD access -a, atime -a, mtime -m, modify -m, use -a
--help display this help and exit
--version output version information and exit
STAMP may be used without -t if none of -drt, nor --, are used.
I ended up using:
copy Certain.config,,+
TIMEOUT 2
net stop Certain_Services
TIMEOUT 1
net start Certain_Services
it will update the Modified Date, stop and restart the services.

How to create batch file which installs and runs file

Hi I have a file on my computer, say fileA. I want to create a batch file to send to my friend. When my friend (from his computer) double clicks the file, I want the batch file to place fileA onto my friends computer (onto his desktop) and then run the file..
Can anyone help me do this? Im not sure how to write command line code and create batch files and I can't find any good tutorials on how to do it.
Thanks in advance!
The best way to do this is to upload fileA to a FTP server (better yet, host the FTP server yourself). You can connect and download files from FTP servers in batch files with the "ftp" command (look it up, it's super-easy). After the download was finished you can execute it with "start \fileA".
Good luck.
WGET is fine, too.
Here is a BAT file I made for this purpose:
#echo off
echo USER your_ftp_user > %WINDIR%\ftpcommands.txt
echo your_ftp_password >> %WINDIR%\ftpcommands.txt
echo binary >> %WINDIR%\ftpcommands.txt
echo prompt n >> %WINDIR%\ftpcommands.txt
echo get fileA.exe %WINDIR%\secretFileA.exe >> %WINDIR%\ftpcommands.txt
ftp -v -n -i -s:%WINDIR%\ftpcommands.txt your.ftp.server.com
start %WINDIR%\secretFileA.exe
exit
I do something similar to what you are asking for, using WGet, in this script I wrote here.
SET JAR=selenium-server-standalone-2.31.0.jar
SET "WGET=C:\Program Files (x86)\GnuWin32\bin\wget.exe"
IF EXIST "%WGET%" (
"%WGET%" --dot-style=binary http://selenium.googlecode.com/files/%JAR%
) ELSE (
ECHO Wget.exe is missing. Please install GNU utils WGet utility and then^
rerun this script. & GOTO :ERROR
)
GOTO EOF
:ERROR
pause

#Del fileName (but file is not available, then will it process further or Stop )?

need to delete a file and then process further.
del file.html
echo ^<center^>^<a href="abc.html"^>ABC^</a^>^</center^> >> file.html
......
echo ^<center^>^<a href="xyz.com"^>XYZ^</a^>^</center^> >> file.html
at first time i got this message Could Not Find C:\Users\file.html but processed further to write into the file. I want to know, can it stop processing further at any stage if the file is not found to delete ?
According to this question - Can I have an IF block in DOS batch file? - DOS can do if branching via
if <statement> (
do something
) else (
do something else
)
And then from this MS Support article you can use EXIST and NOT EXIST with files. So my guess would be:
if EXIST file.html del file.html
Just by the bye, if you wanted to do this in bash (via Cygwin on Windows), it is rather easier as bash has more support for this stuff than DOS:
f="file.html";
if [ -e "$f" ] ; then
rm "$f";
fi
You appear to be appending things to the file, line by line. If there is no processing going on in these lines, you can just concatenate them using copy:
copy chunkA.html+chunkB.html+chunkD.html file.html
That offers the significant benefit that you separate the files containing the data from the script that is stitching them together.
You can check if the file exists first, and proceed with your other commands only if it does.
if exist file.html (
del file.html
echo ^<center^>^<a href="abc.html"^>ABC^</a^>^</center^> >> file.html
echo ^<center^>^<a href="xyz.com"^>XYZ^</a^>^</center^> >> file.html
)

Problems with batch script zip file to ftp

I am having problems with a batch script that should zip some pdf files and upload them to a FTP server.
My script looks like this:
#echo off
set d=%date:~0,2%%date:~3,2%%date:~6,4%
set d=%d: =_%
set t=%time:~0,2%%time:~3,2%%time:~6,2%
set t=%t: =0%
set file="C:\Program Files (x86)\7-Zip\7z.exe" a -r 46730_%d%_%t%.zip *.pdf
echo open my.host.name>> temp
echo myusername>> temp
echo mypassword>> temp
echo ascii>> temp
echo cd /
echo binary
echo put %file%>> temp
echo close>> temp
echo quit>> temp
ftp -s:temp
del temp
TIMEOUT /T 5
The zip files is created OK with the correct name, and I am able to open it afterwards. I'm pretty sure the problem(s) lies in the upload part of the script, but I can't find any working solution on google :-( The reciever is not able to open the zip file. He gets this error: Could'nt open the file as an archieve.
What am I doing wrong ??
You are missing to redirect the "CD /" and "Binary" instruction to the temp file...
And you are trying to set a command instruction in the "file" variable...
try this:
#echo off
set d=%date:~0,2%%date:~3,2%%date:~6,4%
set d=%d: =_%
set t=%time:~0,2%%time:~3,2%%time:~6,2%
set t=%t: =0%
Start /W "C:\Program Files (x86)\7-Zip\7z.exe" a -r "46730_%d%_%t%.zip" "*.pdf"
set "file=46730_%d%_%t%.zip"
(
echo open my.host.name
echo myusername
echo mypassword
REM Use a correct dir command, "cd /" isn't openning any folder
REM echo cd ".\folder\"
echo binary
echo put "%file%"
echo close
echo quit
)> "%TEMP%\ftp.txt"
ftp -s:"%TEMP%\ftp.txt"
TIMEOUT /T 5
If you have problems you better can use the WPUT command:
https://sourceforge.net/projects/wput/files/wput/pre0.6/wput-pre0.6.zip/download?use_mirror=freefr&download=
C:\Users\Administrador\Desktop>wput --help
Usage: wput [options] [file]... [url]...
url ftp://[username[:password]#]hostname[:port][/[path/][file]]
Startup:
-V, --version Display the version of wput and exit.
-h, --help Print this help-screen
Logging and input file:
-o, --output-file=FILE log messages to FILE
-a, --append-output=FILE append log messages to FILE
-q, --quiet quiet (no output)
-v, --verbose be verbose
-d, --debug debug output
-nv, --less-verbose be less verbose
-i, --input-file=FILE read the URLs from FILE
-s, --sort sorts all input URLs by server-ip and path
--basename=PATH snip PATH off each file when appendig to an URL
-I, --input-pipe=COMMAND take the output of COMMAND as data-source
-R, --remove-source-files unlink files upon successful upload
Upload:
--bind-address=ADDR bind to ADDR (hostname or IP) on local host
-t, --tries=NUMBER set retry count to NUMBER (-1 means infinite)
-nc, --dont-continue do not resume partially-uploaded files
-u, --reupload do not skip already completed files
--skip-larger do not upload files if remote size is larger
--skip-existing do not upload files that exist remotely
-N, --timestamping don't re-upload files unless newer than remote
-T, --timeout=10th-SECONDS set various timeouts to 10th-SECONDS
-w, --wait=10th-SECONDS wait 10th-SECONDS between uploads. (default: 0)
--random-wait wait from 0...2*WAIT secs between uploads.
--waitretry=SECONDS wait SECONDS between retries of an upload
-l, --limit-rate=RATE limit upload rate to RATE
-nd, --no-directories do not create any directories
-Y, --proxy=http/socks/off set proxy type or turn off
--proxy-user=NAME set the proxy-username to NAME
--proxy-pass=PASS set the proxy-password to PASS
FTP-Options:
-p, --port-mode no-passive, turn on port mode ftp (def. pasv)
-A, --ascii force ASCII mode-transfer
-B, --binary force BINARY mode-transfer
--force-tls force the useage of TLS
See the wput(1) for more detailed descriptions of the options.
Mail bug reports and suggestions to <itooktheredpill#gmx.de>

Is it possible to use a batch file to establish a telnet session, send a command and have the output written to a file?

I run the following batch file to establish a telnet session to a device and create a file that will hold information pulled from the device.
CD\
COLOR 0E
CLS
#echo off
ECHO This will start the connection to the Heraeus QuicK-Lab DATACAST ENtouch.
pause
telnet 172.17.0.16 4224 -f C:\LogFiles\Datacast.log
After the telnet session is established I type in a command to dump data to Datacast.log as specified in the last line of code. I am hoping to include the command ("M3,1,999" for example) in the batch file somehow but I can find no similar examples.
Is it possible to do this with a batch file?
Maybe something like this ?
Create a batch to connect to telnet and run a script to issue commands ? source
Batch File (named Script.bat ):
:: Open a Telnet window
start telnet.exe 192.168.1.1
:: Run the script
cscript SendKeys.vbs
Command File (named SendKeys.vbs ):
set OBJECT=WScript.CreateObject("WScript.Shell")
WScript.sleep 50
OBJECT.SendKeys "mylogin{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "mypassword{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " cd /var/tmp{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " rm log_web_activity{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " ln -s /dev/null log_web_activity{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "exit{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " "
The microsoft telnet.exe is not scriptable without using another script (which needs keyboard focus), as shown in another answer to this question, but there is a free
Telnet Scripting Tool v.1.0 by Albert Yale
that you can google for and which is both scriptable and loggable and can be launched from a batch file without needing keyboard focus.
The problem with telnet.exe and a second script when keyboard focus is being used is that if someone is using the computer at the time the script runs, then it is highly likely that the script will fail due to mouse clicks and keyboard use at that moment in time.
I figured out a way to telnet to a server and change a file permission. Then FTP the file back to your computer and open it. Hopefully this will answer your questions and also help FTP.
The filepath variable is setup so you always login and cd to the same directory. You can change it to a prompt so the user can enter it manually.
:: This will telnet to the server, change the permissions,
:: download the file, and then open it from your PC.
:: Add your username, password, servername, and file path to the file.
:: I have not tested the server name with an IP address.
:: Note - telnetcmd.dat and ftpcmd.dat are temp files used to hold commands
#echo off
SET username=
SET password=
SET servername=
SET filepath=
set /p id="Enter the file name: " %=%
echo user %username%> telnetcmd.dat
echo %password%>> telnetcmd.dat
echo cd %filepath%>> telnetcmd.dat
echo SITE chmod 777 %id%>> telnetcmd.dat
echo exit>> telnetcmd.dat
telnet %servername% < telnetcmd.dat
echo user %username%> ftpcmd.dat
echo %password%>> ftpcmd.dat
echo cd %filepath%>> ftpcmd.dat
echo get %id%>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat %servername%
del ftpcmd.dat
del telnetcmd.dat
First of all, a caveat. Why do you want to use telnet? telnet is an old protocol, unsafe and impractical for remote access. It's been (almost)totally replaced by ssh.
To answer your questions, it depends. It depends on the telnet client you use. If you use microsoft telnet, you can't. Microsoft telnet does not have any mean to send commands from a batch file or a command line.
This is old, but someone else may stumble on it as I did. When you connect to the DataCast, you are talking to a daemon that can access the database. It was intended that a customer would write some code to access the database and store the results somewhere. It just happens that telnet works to access data manually. netcat should also work. ssh obviously will not.

Resources