Friday, August 3, 2018

Automated Data Transfer - Linux To Windows + Vice Versa

Recently one of the developers where I work had an interesting task to accomplish: Transfer data from a Windows server to a Linux server and vice versa automatically every 5 minutes for a production environment. The data originated at the Windows server, was processed in the Linux server, copied to a different path and the result needed to be copied back to the Windows server, to a different folder. The accounting users were saving the original data to a Windows shared folder. The process needed to originate at the Windows server, since my team mates were not proficient in Linux, in case the files needed to be modified later on

Thanks to WinSCP, the solution was simple:

1) Create a batch file (WinSCP2Linux.bat) with permissions for service account to read and execute. The content should be something similar to this: /ini=nul /synchronize /script=C:\Users\LocalAdmin\ScriptCopyToOracle.txt

2) Create a text file (C:\Users\LocalAdmin\ScriptCopyToOracle.txt), with permissions for service account to read and execute. The content should be something similar to this:

open sftp://LinuxServerUsername:LinuxServerUserPassword@LinuxServerName/ -hostkey="ssh-rsa 2048 xx:yy:zz:aa:bb:cc..."
put C:\Path\To\Windows\Original\Files\* /path/to/Linux/server/firstfolder/
get /path/to/Linux/server/secondfolder/* C:\Path\To\Windows\Processed\Files\

Note: LinuxServerUsername requires read and write permissions to both Linux folders for this procedure to work. Both Windows folders have read and write permissions

3) Create a task via "Task Scheduler" which runs the batch file every 5 minutes and runs under the service account specified in step 1)

The task will only synchronize files that are not in the folders every 5 minutes. I would recommend testing if the task works by opening an elevated command prompt ("Start", cmd, right click, "Run as administrator"), pasting /ini=nul /synchronize /script=C:\Users\LocalAdmin\ScriptCopyToOracle.txt into it and hitting the "Enter" key. If there are no errors, you should see the processed files in the firstfolder in Linux and in the processed files folder in Windows

The Linux server was running Red Hat Linux and the Windows server was on Windows Server 2012


F. Bobbio C.

Corrupted Profile - In A Mac

Any IT professional that deals with users needs to know a bit of other Operating Systems. The three main ones currently are Windows, macOS and Linux.

I recently had a case where a customer using a Mac could not open any application. When the application icon was clicked, there were errors pointing to the Library folder and cache. All applications had the same issue. I thought about it for some minutes and logged out and back in, but under a different profile. The other profile did not display those issues, thus the issue being with the original profile

I created a new profile with Administrator priviledges (that was the access level for the original profile) and copied all documents over, thinking that all permissions would transfer, but, how wrong was I! The permissions for the iPhoto and Photo libraries did not transfer. They were under OriginalUser:OriginalGroup and the new user was NewUser:staff and when the customer tried to open iPhoto or Photos, there was an error about permissions

I had to use a bit of "command line" (or console/terminal) "magic" and change the permissions for the whole folder/application. I logged out and back in with another Administrator account, since the new user account did not allow me for the change. The other account did not have any password, which did not allow for sudo access. I changed the password and ran the commands, each in a different terminal session. Click on the upper right corner on "Spotlight" and type terminal. Open the application. Right click on the application icon on the lower bar and "New window" for the second terminal session

First terminal session:
sudo chown -R NewUser:staff /Users/NewUser/Pictures/iPhoto Library.photolibrary

Second terminal session:
sudo chown -R NewUser:staff /Users/NewUser/Pictures/Photos Library.photoslibrary/

Let both commands run until they finish. In this case, the customer had well over 250 GB of pictures in each application. The process took all night long. Once the terminal session showed the MacDeviceName:~ AdminUser$ prompt in each terminal session, the customer closed everything (Command + Q in each window) and logged out and back in. The customer reported all the pictures were accessible and viewable. No more permissions errors

I hope this helps someone


F. Bobbio C.