Unix programming to copy to clipboard - excel

Any idea if i can use a unix command to copy text from a file in unix onto my clipboard?
I can't use xclip and xsel as my company doesn't allow me to install utils.
Hence i am wondering if there is any workaround
If anybody needs a background to what i am doing here goes:
I am using an excel macro to launch putty and then send commands to putty using the excel macro. Part of this process requires me to copy text or certain text to my clipboard and paste it in an active cell in my excel sheet.

It is unlikely that xclip or xsel would be useful here, unless you actually start an X application from PuTTY.
If your excel macros allow the capture of any command output, you could use Plink, the cli tool which is included in a full PuTTY installation. You still need to address any issues with remote access (creating and managing public/private keypairs for authentication.)
Check the PuTTY docs for more information.

Related

How to create excel file by copying CSV files and running VBA macros remotely from Linux

I'm running some task on Linux which produces certain CSVs. Once they’re produced, I need to copy them into different sheets of an excel file and then run some VBA macros to generate a report. Since this has to be done multiple times a day (with no pre-defined/fixed schedule), I’d like to automate it.
Here is what I tried:
I wrote a VBScript, which takes the CSV files and other required input files, opens an excel file, copies the CSVs into the excel, runs some VBA macros, and saves and closes the result. This VBScript works fine when triggered locally on a windows server.
I have uploaded a simpler version of the files involved here which somewhat clarify my requirements (Note that the macros I need to run are much more complicated (~500 lines) compared with the macros here).
There are four files inside the archive:
Template.xlsm: The Excel template of the report into which data is to be pasted
Input_Sheet2.csv : The input data to be pasted into the template into sheet 2
Input_Sheet3.csv : The input data to be pasted into the template into sheet 3
Run.vbs: The vbscript which triggers the “copy-paste” macro present inside the Excel template.
The command to run the VBScript is: ‘cscript //Nologo Run.vbs /NoCancel’
Now, in order to automate whole task, I thought to trigger this VBScript remotely from Linux over ssh. I installed the cygwin ssh daemon on the windows box and facilitated ssh connections from the Linux machine. This cygwin ssh connection from Linux allows to run several windows commands, but fails to run the VBScript and doesn't produce any excel output.
I can't figure out which component has limitations. Is it cygwin ssh not facilitating execution of VBScript? Is it VBScript not facilitating creation of files remotely? Is it ssh client on Linux not allowing opening of excel in GUI format? Or there is another way to automate this task from Linux.
Thanks,
Shubham
I'd focus on:
Did you test running your script from the Cygwin Terminal? (I did try a simple script, that opened Execl (.Visible = True) successfully, so I believe your fears concerning cygwin not allowing to open the Excel GUI are unnecessary).
Do the sshd user account's path and cwd allow the short invocation "cscript Run.vbs" or should the long version "/cygdrive/c/WINDOWS/system32/cscript.exe /home/user/Run.vbs" be used?
Does the sshd user have access/permissions to all involved files and folders?
You didn't forget the unix file systems are case sensitive? (I did and wasted some time)?

Trying to append the Excel file through unix via command prompt

What needs to be done?
I need to make a connection to the remote machine through UNIX, go to the shared drive, open an excel file, save it and close it. This needs to written in an script.
The file contains macros so they needs to be opened manually on daily basis, save it and close it. We plan to write a script that would run on daily basis and refresh this file automatically.
Where am i facing the issue?
Making a connection to the remote machine is done, after that i run certains commands:
1. Open the command prompt
2. cd the file path
3. Open the File
Now this is where the issue starts
How to save the file automatically?
How to close that file?
I tried using the taskill option and it almost worked but it gives out the popup of Do you want to save the file and i dont know how to provide output to that popup through command prompt.
Let me know if you have any idea on how to move ahead on this.
A bit hackish, but xdotool, a program which simulates mouse clicks and keyboard presses could be used. If Windows is being used, then see this question for tools which simulate mouse clicks and keyboard presses.
Have you tried SendKeys?
That may help.

Copying text from linux to windows notepad

I would like to know, how to copy the entire lines of text from vi editor in Redhat to a notepad in windows.
If the size of the text to be copied is minimal, it can be easily done by selecting the lines through mouse and copying to notepad. However I have come across the situation of copying thousands of lines.
I would rather use a file as the media, and use the sz -be coomand send the file to windows.As a suggestion, you can search google about rz/sz command for more details.
If i say straight forward answer then there is no way i guess,
but workaround is there,
Make a public share of samba (not more than 1 min)
Access from windows
Create empty file from windows
At Linux box run
cat {path_to_file_you_want_to_copy_content} >> /public/empty_file
for eg:
cat abc >> /public/empty.txt
Hope that resolves your problem.
If i say straight forward answer then there is no way i guess..,
but try below use cases..,
download and install winscp software and connect to your instance (your linux machine) using username and password. Then copy your files from linux to windows.
if your linux is a virtual machine (running on putty or vmware) using mouse you can directly copy the conent of file in vi editor in linux machine and paste in new or existed file in windows.

Linux emacs/nano: how to select all text lines in a larger file and copy

I need to copy all text in large log files to clipboard. I have a remote connection to Linux and use the console terminal only. What I want is something like Select all -> Copy.
In emacs I used F10 -> Edit -> Select All, and then F10 again -> Edit -> Copy. But it didn't go to my clipboard, unable to paste it in my local windows instance (which works fine with the content displayed on screen; without scrolling).
Is there a better way in nano or emacs?
Cheers
Emacs has a very under-publicized capability that could make your life easier. You can actually open files remotely via ssh, just as easily as a local file, and with very little overhead. So as long as you can copy to clipboard from your local emacs, you can do what you need.
To open a file remotely, just hit C-x C-f as usual. But the file you want is something like
/ssh:otherserver.some.org:/path/to/file.log
where otherserver.some.org is replaced by the actual server name and /path/to/file.log is your actual path. After the first connection, tab completion also works. Editing works exactly as it does with a local file (including copying), except that when you save, the file is copied back to the remote via ssh.
This facility is called "TRAMP", so there will be hidden buffers with "tramp" in their names. Also note that tramp can use several other methods to connect to files, such as plink for Windows, and su to edit files as another user.
Other options for your problem are discussed here:
Getting Items on the Local Clipboard from a Remote SSH Session, or maybe even here:
http://winscp.net/eng/docs/task_edit.
If you have just a terminal session, then there is no way for emacs, nano or any other program running on the Linux side to send text to the Windows clipboard.
Your options are to connect by X11 or VNC, in which case it becomes possible to share a clipboard between Windows and Linux programs, or to copy the file by some other means.
If you are logging in by ssh, you could for example run ssh thelinuxmachine cat /the/log/file/locatioin > logfile.txt in a windows command shell. Connecting to the linux machine using an scp client such as http://winscp.net/ would probably also work.

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.

Resources