GUI wrapper for cygwin scripts? - cygwin

I use some minor scripts at work under cygwin, and I would like to make them available to workmates with a familiar Windows icon. For instance, suppose I have the following:
cat *tsv | sort > combined_n_sorted.txt
Is there a simple way to make a corresponding icon, assuming cygwin is installed in my workmates' systems? These scripts may involve (cygwin's) python.
Thanks!

It seems that your question has two parts:
How to make scripts accessible on users' desktops.
How to give the each script a particular icon.
For (1), you could create a shortcut on the users' desktops that runs the following command:
C:\cygwin\bin\bash.exe -c 'cat *tsv | sort > combined_n_sorted.txt'
or if the commands are stored in a script,
C:\cygwin\bin\bash.exe -c /path/to/script
If you want to hide the console window from appearing while the script runs, you could use the run command (in the run package), e.g.:
C:\cygwin\bin\run.exe /bin/bash -c 'cat *tsv | sort > combined_n_sorted.txt'
# or
C:\cygwin\bin\run.exe /path/to/script
But it might be better for users to see the console window, so they know the script is running.
For (2), you can change each shortcut's icon individually by right-clicking on it and choosing Properties, but AFAIK that's a one-host-at-a-time change. I don't know of any batch way to do it, although no doubt there's a registry key you can set. Or, if you change the icon of the shortcut on your host and then distribute that shortcut, it might keep the same icon on other users' desktops, if the icon is a standard one that exists on their hosts.

Related

Get window list sorted by most recent access bash

I know you can do wmctrl -l to list all open windows with their ids.
I would like to have this list sorted by most recent access (the same order as when you do Alt+Tab), is they any way with wmctrl or with any other command line utilities ?
I'm using xfce4, if you know a way to do it with it
I'm sorry but I don't think it is possible.
getting a list of open windows is easy to export to bash because
it is manages by the OS.
however, visualizations (such as "windows order") is not managed by the OS.
Only the window manager (Explorer for windows, Nautilus for ubuntu, Cinnamon for mint, etc) hold that kind of information. Os can work fine without GUI (using tty only, you can read text, write text, even surf the internet). Windows order means something for the window manager only :(
therefore you either have to access the process memory and parse it or hope for and api exported from the process (which I don't think will happen). Either way you choose, it won't work for more than one specific window manager.
I'm sorry...
xprop -root | grep _NET_CLIENT_LIST_STACKING(WINDOW

How to automatically open prompts, ssh, and do things using a script?

I have to connect to a linux server from my own Ubuntu machine and operate directly on the server.
A dozen of folder names are listed in a LIST file. How to write sth. (like a bash script?) to carry out the following procedures?
for fold_name in LIST {
/******on my own Ubuntu*******/
-- open 2 new tabs of prompt terminal
-- run an ssh command in both
-- then input passwd and log in automatically in both
/******on the linux server*******/
-- cd to directory xxx/fold_name in both
-- run aaa.exe in 1st tab
-- vim sth in the 2nd tab
}
Once the loop of open-tab-login is solved, I guess the second part is routine as simple bash script except that I don't know how to specify between 2 tabs, either.
The point is I want all tabs in the same terminal. To this end, manually, I often Ctrl+Alt+T to create a prompt and Ctrl+Shift+T to open many tabs within it. And ssh...cd...... in each one. You see how annoying and cumbersome it is!
There are a few things you might like to research, which will get you a little closer.
You can run an ssh without a password, if you use an ssh key. Check out ssh-keygen, and the -i option in ssh.
Opening up tabs in gnome-terminal can be done via the method described here: Open a new tab in gnome-terminal using command line
You can run specific commands (e.g. aaa.exe) on a remote box over ssh, by including the command after the ssh: ssh user#remotehost aaa.exe.
If you want multiple commands, try enclosing them in quotes: ssh user#remotehost "cd /xxx; aaa.exe". Vim does not need to be in the directory in question in most cases: ssh user#remotehost vim /xxx/filename"
If you want to do something interactive (like vim), include the -t flag in ssh.
The tabs will be independent of each other - I'd probably run half of the command in one window, the other (e.g. runnning aaa.exe in one window, using one command, and the vim in another window, using another command, that I just happen to run at the same time. This way I can resize the windows, and arrange them relative to each other, and see both at once.
-- open 2 new tabs of prompt terminal
This depends on which desktop you're using. For gnome, gnome-terminal takes the -e option to specify the script to execute in the new terminal window. So, for something like this, you would execute gnome-terminal -e $script &, placing each instance of gnome-terminal in the background.
If you're using a different desktop, other terminal applications typically have a similar option. So, you'd point the terminal application to a script that's going to run in the terminal, and complete the rest of your task for you.
-- run an ssh command in both
-- then input passwd and log in automatically in both
This is going to be more complicated. The classical solution is the expect utility. There might be other similar tools that do similar things, but expect is pretty much the usual way these kinds of things have been done in the past. When it comes to trying to automate an interactive application, expect is really the only way to go. Unfortunately, expect uses a somewhat arkane syntax, that first-time users typically find confusing, and hard to understand. I grumble, every time I see no other alternative but to use expect to automate something, but this is pretty much the only option that's usually available.

Name screen session log using session name

I'm using this very simple .screenrc:
logtstamp on
logfile /tmp/screenlog-%S.log
I tried launching screens with these two methods:
screen -L -S testing
screen -S tester -L
but the filename used is /tmp/screenlog.0S.log. What am I doing wrong? Using Screen version 4.00.03jw4 (FAU) 2-May-06, and according to the manual I should be able to name the log file using the session name
If you look at the man page (man screen) for your (8-year-old?) version of screen, you'll see it's missing the %S specifier. They must have added it since your version. I'm not sure why Ubuntu 12.04 shipped screen from 2006..
P.S. I'd advocate looking into tmux. It's a little bit harder to learn, but a lot more flexible: You can move windows between sessions, You can see multiple windows at once, You can nest sessions inside of other sessions, etc.
Also, if you are just looking to log the output of long-running processes, take a look at nohup.

Duplicate keyboard typing to another terminal

I have laptop-desktop setup at home and I have successfully cloned my Archlinux installation from one to another. However, I would like to avoid having to {install all new software, edit settings, update} twice, so I was wondering if it'd be possible to log over ssh from laptop to desktop, do something in terminal and have linux copy everything I type into second terminal with ssh logged in?
Thanks for ideas!
You could type the commands into one terminal then edit ~/.bash_history and save the commands into a script. Copy the script onto the machine with the second terminal and execute it. The advantage of this is now you have a script that saved your setup so you can reuse it whenever you need to.
You can use clusterssh, which duplicates your typed input across multiple systems. It is designed for situations in which the exact same tasks, such as software installation or configuration commands, are needed to be performed exactly the same on multiple systems. See http://sourceforge.net/projects/clusterssh/. Also, the KDE Konsole terminal has similar functionality.

load linux screen setups from file

I use linux screen heavily , generally if the OS didn't restart or say as long as the SCREEN process is there, I can re-attach to my terminals.
But I don't want to set-up the screens each time after my computer restarts that's tedious work.
so I generally setup a series of screens to run different categories of command
1. create a window, rename the screen, run specific command
2. etc...
Is there a way to create these screen setups automatically , say can I script to do that ?
Edit: what is more important here is how to paste some command into the window after the window is created.
Yes, of course.
You just need to specify the configuration of screen in ~/.screenrc.
If you want to use several configurations, you can create several config files
and start screens with -c key.
screen -c ~/.screenrc1
screen -c ~/.screenrc2
screen -c ~/.screenrc3
Example of ~/.screenrc:
screen -t news 8 newsbeuter
screen -t jabber 9 freetalk
here will be open two windows: on 8 -- newsbeuter (the name of the window news); on 9 — freetalk (the name of the window jabber).

Resources