Change size of files on Windows machine from remote Linux machine - cygwin

I need to change somehow size of files (increase or decrease) on Windows machine using bash scripts. (Content of files doesnt matter) But i have to run this scripts from remote linux machine. I've selected truncate command for size changing, this is exactly that i need, cause i need to change size exactly of chosen file, without changing it's descriptor. It is very important.
But i DO NOT have truncate on my linux machine and i CANNOT install it there (So dont tell me to install it there plz :)). I cannot install nothing on my linux machine it has specific kernel - this is a main option of all my problems.
So i've decided to install cygwin on my Windows machine, cause it has truncate command. Also i know that there are fallocate command, but my linux machine also doesnt have it, and cygwin doesnt have it too. So if there is some another command i wanna know it :)
Then after this steps i tried to change file size from cygwin terminal via truncate and all works perfectly. And the last problem that i had to solve was just run cygwin's bash from my remote linux, i've chosen winexe for that.
Finally the way that i've chosen is:
I run winexe command on my linux machine that runs:
winexe myHost "c:\cygwin\bin\bash.exe myScriptWithTRUNCATE"
on my Win machine.
But it doesnt work and i dunno why. truncate command doesnt change size of files at all. When i type
truncate --help
all works, i can see result of help option on my linux terminal, but e.g.
truncate -s someSize myFile
doesnt work, size of file doesnt change. Also error code from truncate -s someSize myFile is 0
Any suggestions?

try giving the name of your script that is "myScriptWithTRUNCATE" directly in winexe command .
example:-
winexe myHost "c:\cygwin\bin\bash.exe myScriptWithTRUNCATE"
also check debug log of winexe by modifying winexe command as :-
winexe -d 5 myHost "c:\cygwin\bin\bash.exe myScriptWithTRUNCATE"
see in this log what actually is sent over to windows as command in place for your script.
specifically see in " CTRL: sending command : run xxxxx"
see what "xxxxx" is in that debug log.
winexe gives you the control of windows command line(cmd.exe).
Try running you script after it has got control of cmd.exe.
Based on some findings above , try this link for more help
http://blog.dotsmart.net/2011/01/27/executing-cygwin-bash-scripts-on-windows/

Related

Command not found in WSL2 even though it's on the path

I'm having an issue with WSL2:
$ where b4a
/usr/local/bin/b4a
$ b4a new
/usr/local/bin/b4a: 1: Not: not found
Even though where finds commands, I can't run them. And it's not a PATH issue either:
echo $PATH
/usr/local/sbin:/usr/local/bin:[...]
And b4a isn't the only command with this problem. What could be the cause? My distribution is Debian 10 and host is Windows 10.
Not necessarily a full answer, but hopefully the troubleshooting methods you need to arrive at a solution ...
Note that it doesn't say that the command itself isn't found. For instance, if you run:
# lllllllllll
lllllllllll: command not found
That's truly a command not found. This is different. While I don't (yet) know the exact cause, this seems closer to the issues we might see with improperly quoted paths with spaces in a shell script.
You mention that other commands have this problem -- Is there something in common with the commands that don't work properly? Is it possible that they are all shell scripts?
Try several things to debug:
Start WSL without your startup profile. It's very likely that something (or you) added a line that is causing problems. From PowerShell or CMD:
wsl ~ -e bash --noprofile --norc
b4a
If that works, then there's a problem in one of your startup files that you'll need to debug. Look for anything modifying environment variables without proper quoting, especially the PATH. WSL automatically appends the Windows path to your Linux path to make it easy to run Windows commands, but the fact that almost every Windows path has spaces in it can cause problems for unsuspecting scripters that don't take this corner case into account.
Having a space in a path is fully allowed in Linux, but some scripts just don't handle it properly.
If the command that is failing is a shell script, trying starting it with:
bash -x /usr/local/bin/b4a
Or even start WSL with wsl ~ -e bash -x to see all trace output from the shell.
In this case, you'll be looking for some problem in the script right around where it actually fails.
If all else fails, you can disable WSL's PATH modification via its config file:
sudo -e /etc/wsl.conf
Add the following:
[interop]
appendWindowsPath = false
Then exit Debian, run wsl --shutdown and restart Debian. Try the b4a command again.
If this works, then the problem is almost certainly due to some problem in the PATH quoting in these commands. I don't recommend it as a permanent solution since you will have to type out the full path of Windows applications each time you want to run them.

nvim started as desktop application | :checkhealth - commands not available

When I start neovide from my applications and run :checkhealth I get errors that node and other commands are not available. But when I start it from my terminal there is no error for those commands. I tried to copy and modify the neovide desktop file to start just nvim and see if there if something wrong with my my neovide installation. But also starting just nvim as application prints the same errors.
I'm using linux with plasma desktop
TL:DR; add a path variable
Depending on your configuration, nvim will need to know the environment to run some executables (like it is with node in your example). An easy solution is to add the path variable to the exec command in the according .desktop file. I remember that I had the same issue with node not being recognized in a configuration using my plasma installation. On gnome node was recognized and healthchecks were good, so I thought I didn't need the extra path. Later on I realized that I had trouble with other commands. E.g. when using fdfind to complete path commands. Again I had to search what the reason was and it also was the missing path.
To give an example, let's say you are using zsh and want to start neovide with multigrid enabled, the Exec line in your desktop file could look like:
Exec=zsh -c "source ~/.config/zsh/.zshrc && neovide --multigrid %F"

Translating Linux command prompt to windows PowerShell prompt

Quick background: I previously used a remote Linux server for a project. Here I was able to pull up the Linux command window in the directory where files from another program were located, and enter a command such as lspp c= example_file.cfile -nographics. LSPP in this case is short for LS PrePost - through this command I was able to call LSPP in the background and have it reference the given *.cfile which contains various commands to be executed, such as depositing a given *.csv file with results, its name, etc.
I recently managed to install LSPP for windows locally, and am now trying to essentially translate the functionality of the command I executed in Linux, to Windows. I should add that I have no experience with CMD or Windows PowerShell...
The first thing I tried was to use cd C:\.... to set the directory to where the *.cfile is located and then enter the same lspp c= example_file.cfile -nographics from Linux, however, the response was that "lspp" was either spelled wrong or could not be found.
Next I tried setting the directory to the LSPP program folder, and using start LS-PrePost-4.7-x64 to at least start the program, but this didn't work either.
I would really appreciate it if someone could point me in the right direction here - thank you!

psexec error code -1073740771

I'm trying to open up a Unity3D game.exe that is on a remote computer through my main desktop. I had tried to do this through a batch file, but was advised to try PsExec in its place.
So far, I've brought the Psexec program into my game.exe folder. I run the command line required to open the program and the window opens up for a fraction of a second before closing down due to an error. The error code it gives is: -1073740771.
I tried googling what this error actually is but I can't find anything. Does anyone know what this error relates to?
The command line I type is as follows:
psexec \\OtherComputer -i C:\Administrator\Users\Desktop\TargetFolder\Target.exe
I even tried the above line with -d after the -i, quotes around the C:... but it all results in the same thing.
PSExec wont know about other game resources that live without side the EXE. It will simply copy game.exe to the remote machine and execute it.
Try deleting or renaming the resource folder and running it on your local machine - it should do the same thing as its doing on the remote machine.
You cant do what you want with psexec unless the entire application is self contained within one single .exe file.
You may be able to manually copy the resource folders if you have admin access to the other machines and administrative shares are enabled, then execute with psexec using the -w option:
Copy the files to \\OtherComputer\C$\MyGame
Run psexec \\OtherComputer -w C:\MyGame -i C:\Administrator\Users\Desktop\TargetFolder\Target.exe
Might work ;o)
Use the -h parameter to elevate the permissions.

Cygwin error: "-bash: fork: retry: Resource temporarily unavailable"

I recently reinstalled Cygwin on my computer in order to get access to several command line elements that I was missing. I have never had previous difficulty with Cygwin, but after this reinstallation, an error message continues to appear after (almost) each command entered. For instance:
-bash-4.1$ wc m1.txt
3 [main] bash 2216 child_info_fork::abort: data segment start: parent(0x26D000) != child(0x38D000)
-bash: fork: retry: Resource temporarily unavailable
2013930 4027950 74968256 m1.txt
Generally, the command still runs (as seen above), but not always. Occasionally, the 'error' message occurs several times in a row (the initial number "3" will then change to a "4" or "2", notably if I start a second Cygwin window.
Also, as soon as I start up Cygwin, I get the following message before the prompt:
3 [main] bash 6140 child_info_fork::abort: data segment start: parent(0x26D000) != child(0x36D000)
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: Resource temporarily unavailable
-bash-4.1$
At the moment, I am debating whether to uninstall/reinstall Cygwin again or just live with the error messages, but I was curious if there might be an issue that I am unaware of.
(assuming Cygwin is installed at C:\Cygwin):
Open Task Manager and close any processes that look to be Cygwin related.
Open C:\Cygwin\bin in Windows Explorer
Verify that dash.exe, ash.exe, rebase.exe, and rebaseall exist in this folder
If any of them are missing, re-run Cygwin setup and select the dash, ash, and rebase packages
right-click your C:\Cygwin folder, uncheck Read-only (if its checked), and press OK.
When an error about not being able to switch some files comes up, select "Ignore All". Wait for this process to complete.
Browse to C:\Cygwin\bin in Windows Explorer
Right click dash.exe and click "Run as Administrator". A command Prompt should appear with nothing but a $
Type /usr/bin/rebaseall -v, hit enter, and wait for the process to complete.
If you get errors about Cygwin processes running, try Step 1 again. If that still doesn't work, Restart your computer into safe mode and try these steps again.
A commenter noted that, depending on your settings, you may have to type cd /usr/bin && ./rebaseall -v instead.
Try opening Cygwin again.
This process worked for me. I hope it works for you guys too.
Source: http://cygwin.wikia.com/wiki/Rebaseall
I would like to add the following to the above answers, as it is what I had to do after reinstalling Cygwin:
Navigate to the "/usr/bin" directory (usually, C:\cygwin\bin) and right click, Run as Administrator the file: dash.exe
Then, at the $ prompt type the following, hitting enter after each line:
cd /usr/bin/
/usr/bin/peflags * -d 1
/usr/bin/rebaseall -v
What it does is, it marks the dll's as "rebase-able," and then rebases them. You have to have peflags.exe in addition to the above files (in previous answers). You may have to restart windows after doing this and you will definitely need to make sure that there are no processes nor services belonging to cygwin running. (Use task manager, kill any related processes, and then under the services tab look for any service starting with CYG and stop it.)
After doing this, I was able to get cygwin to run without any errors about dll's being loaded to the wrong addresses aka fork errors, etc.
I hope that this helps others, as it was a pain to find.
SOURCE: http://www.cygwin.com/faq.html#faq.using.fixing-fork-failures
and the rebase README file.
To add on to other answers here, we ran into the same issue but could not run the rebase command from the ash or dash shell. However, when launching the command from the Windows cmd shell, the following worked.
cmd /c "C:\cygwin64\bin\ash.exe /usr/rebaseall -v"
-v is to get verbose output
I found another information here :
http://cygwin.com/ml/cygwin/2014-02/msg00531.html
You have to delete the database at
/etc/rebase.db* and do in a "ash" windows :
peflags * -d 1
rebaseall
It works for me on 2 servers.
I solved this problem by restarting my computer. Probably installed a driver update and kept using sleep instead of shutting down.
Experienced the same issue when loading Cygwin with cygiconv-2.dll forking and not loading successfully in the Cygwin terminal, but after turning off my AntiVirus (it was specifically Ad-aware), the issue resolved, and Cygwin worked properly.
In case you are using babun's Cygwin, after rebaseall, try launching Cygwin by executing .babun\cygwin\cygwin.bat in a Windows command prompt or Windows explorer.
This works for me (while launching babun's default console - mintty results in fork error).
I had the error on win10 and i was trying to rebase to c: before install.
then i saw that the installer was installing it instead to c:/Users/myuser
so i was coping all files from c:/Users/myuser to c:.badun
and then restart plus open badun.bat
not shure if this was wise its now duplicated XD... but then it worked again.
Rebaseing didn't help in my case. In addition to what other people suggested, I noticed that reducing the length of PATH environment variable fixed the issue for me (and for other people as well as can be seen from this answer).
This issue is intermittent in nature & I found this issue when there is network is too slow to connect to remote machine on AWS.... I have Shell script that runs through Gitbash shell & it connects to AWS EC2 instance with ssh..... Most of the time, it ran correctly but 2 out 100 times it get into this issue bash: fork: retry: Resource temporarily unavailable .... Killing the MSYS2 terminal from task manager helps to overcome with this issue....
Negative side is you need to run the scripts from the beginning...
I had the same issue on Windows 10 and the mobaxterm app (which uses cygwin) and I tried all of answers listed here however for me, the solution was to simply delete the "CryptoPro CSP" application.
I started facing this problem after upgrading to windows 10. As of now I do not see that any of the above method working.
What I am noticing is that if you start cygwin with admin right (right click and say "run as admin") then it works fine.
Or you open cmd as administrator and then launch cygwin from there, then also it runs fine.
Just reinstall cygwin and select TCL and activate EXPECT

Resources