Sponsored Content
Top Forums Shell Programming and Scripting Execute powershell script with UNIX Post 303007190 by drl on Monday 13th of November 2017 09:01:42 AM
Old 11-13-2017
Hi.

I recently installed Powershell (pwsh).

This script:
Code:
#!/usr/bin/env pwsh                                                                                                                                             function FuncCheckService                                                       

{
        $ServiceName = 'pgsql-9.2'
        $arrService = Get-Service -Name $ServiceName

                if ($arrService.Status -eq 'Running')
                        { 
                                Write-Output "$ServiceName service is running"
                        }
                else
                          { 
                                 Write-Output "$ServiceName service is not running"
                        }
                        }

#start transscript to log details
 Start-Transcript -Path "C:\Users\sup_jelborough\Documents\CheckPostgresService.log" -Append -IncludeInvocationHeader

#Call function with EM service as a parameter
 FuncCheckService pgsql-9.2

#stop logging
 Stop-Transcript

produces:
Code:
> ./s1                                    
Start-Transcript : Transcription cannot be started due to the error: Cannot 
find drive. A drive with the name 'C' does not exist.
At line:20 char:2
+  Start-Transcript -Path "C:\Users\sup_jelborough\Documents\CheckPostg ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Transcript], PSInva 
   lidOperationException
    + FullyQualifiedErrorId : CannotStartTranscription,Microsoft.PowerShell.Co 
   mmands.StartTranscriptCommand
 
Get-Service : The term 'Get-Service' is not recognized as the name of a 
cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the 
path is correct and try again.
At line:7 char:16
+     $arrService = Get-Service -Name $ServiceName
+                   ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Service:String) [], Command 
   NotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
pgsql-9.2 service is not running
Stop-Transcript : An error occurred stopping transcription: The host is not 
currently transcribing.
At line:26 char:2
+  Stop-Transcript
+  ~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Stop-Transcript], PSInval 
   idOperationException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.S 
   topTranscriptCommand

Not surprising because I don't have your environment. The Get-service issue might be a problem.

This was run on a system like:
Code:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.9 (jessie) 
pwsh PowerShell v6.0.0-beta.9

More details about pwsh:
Code:
pwsh    PowerShell command-line shell and .NET REPL (man)
Path    : /usr/bin/pwsh
Package : powershell
Version : v6.0.0-beta.9
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYS ...)
Home    : https://github.com/PowerShell/PowerShell/releases/ (doc)

Good luck ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute SQL query in unix script

Hi I am new in unix. oracle and unix are installed in my sytem.i need the script which could connect to the oracle using username ,password and schema and can run the select * from tab query. Thanks vijay (8 Replies)
Discussion started by: vijays3
8 Replies

2. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

3. Shell Programming and Scripting

Can't execute unix script from SAP BO DI

Dear all, I am very new to UNIX but and need some help in order to make BO DI Job Server execute a .sh script. My unix script has set permissions as under: -rwxrwxrwx. What I m trying to do is move a .txt file from one directory to another on UNIX server. I have full access to Feed... (7 Replies)
Discussion started by: sapbibodi
7 Replies

4. UNIX for Dummies Questions & Answers

commands to execute unix script

commands to execute unix script (1 Reply)
Discussion started by: sunilamarnadh
1 Replies

5. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

6. Windows & DOS: Issues & Discussions

Powershell Script Help

Need some help getting this script to work. can someone help. I am trying to create a script that moves log files to another location and only keeps 60 days worth. please see script I started but having issue getting to work.. $TODAY=GET-DATE GET-CHILDITEM C:\test\*.LOG | Where {... (9 Replies)
Discussion started by: freedavis
9 Replies

7. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

8. Shell Programming and Scripting

Powershell script to monitor windows process

Hello Friend, I am not expert in power shell scripting. I nee custom powershell script which check if given process is running on windows machine or not. will use it in nagios to monitor that process. (0 Replies)
Discussion started by: ghpradeep
0 Replies

9. UNIX for Advanced & Expert Users

Running Powershell Script from Linux through Cygwin

Hello Experts, I am creating a run time powershell script on Linux machine and copying that powershell script to Windows machine. To connect to windows through "ssh", I am using Cygwin tool. To make the connection password less I copied my public in authorized_keys in windows Administrator... (5 Replies)
Discussion started by: shekhar_4_u
5 Replies

10. UNIX for Beginners Questions & Answers

powershell script to unix shell script conversion.

Here is a powershell script to use restful API to create ticket in our ticketing tool. Can anyone please convert it to a shell script sothat, I can run it in Unix servers, below is the code: $body = @{ Customer= ''test' Summary= 'test summary' Impact= '4-Minor/Localized' ... (2 Replies)
Discussion started by: pandeybhavesh18
2 Replies
All times are GMT -4. The time now is 02:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy