scripting

Bash Deployment Script Permission Problem

a 夏天 提交于 2019-12-31 04:54:32
问题 I'm writing a deployment script and have run in to a strange problem... ian@baster:~$ sudo echo "Build: "$REVISION" - Deployed: "$(date +%Y-%m-%d) > /home/www/prod/www/revision.html -bash: /home/www/prod/www/revision.html: Permission denied but... root@baster:~# echo "Build: "$REVISION" - Deployed: "$(date +%Y-%m-%d) > /home/www/prod/www/revision.html root@baster:~# more /home/www/prod/www/revision.html Build: - Deployed: 2011-01-28 then... ian@baster:~$ sudo ls -l /home/www/prod/www total 28

Kill a process on multiple remote machines

天大地大妈咪最大 提交于 2019-12-31 03:30:48
问题 I am looking as the title says to kill a process (for example name.exe) on multiple remote machines. I can do it individually using pskill or taskkill using (for example): pskill -t \ -u -p name.exe but this becomes impractical with 50+ machines. Is there a way to make it read a text file of IP Addresses like psexec does using the @C:\name.txt or in powershell or something similar? All devices are on the same domain. Thank you in advance for your help. 回答1: If you have a text file with a list

Set errorlevel from batch-file

不羁岁月 提交于 2019-12-31 03:11:23
问题 I am working on this complicated (for me...) automation and one part is a batch script Started (not Called) from another one. Now, it's all work-in-progress and I'd like to be able to replace the Started batch script with a simple instruction that would do such that the Start-ing script, after having started the child script, has: %ERRORLEVEL% EQU 1 (And then I could work on the error-handling aspects and test stuff) But also something nice that doesn't put the system in an unnatural state

jscript - getting list of files in directory

放肆的年华 提交于 2019-12-31 02:46:11
问题 This seems like it should be easy. I've never used JScript before and I'm looking at the JScript api provided by microsoft but no luck. Here's what I have: var fso, tf; fso = new ActiveXObject("Scripting.FileSystemObject"); tf = fso.CreateTextFile("New Tracks.txt", true); var objShell = new ActiveXObject("Shell.Application"); var lib; lib = objShell.BrowseForFolder(0,"Select Library Folder",0); items = lib.Items() for (i=0;i<items.Count;i++) { fitem = items[i]; tf.WriteLine(fitem.Name); }

How can I calculate the date preceding a given date in unix?

耗尽温柔 提交于 2019-12-31 02:42:25
问题 I have two variables: X and Y. The value of X will be a date given in the format mmddyy and I want to calculate the date preceding that date and have it be returned in in the format yyyymmdd . Let me give you an example. When X="091509" ( mmddyy format) Y should be "20090914" ( yyyymmdd format) 回答1: ~$ date -d "20090101 -1 day" Wed Dec 31 00:00:00 CET 2008 And if you want to retrieve the date in a custom format you just throw in some format strings. ~$ date -d "2009-09-15 -1 day" +%Y%m%d

Windows Scripting: VBScript, DOS, JS, Python,

回眸只為那壹抹淺笑 提交于 2019-12-31 00:50:08
问题 Say you were mainly a C-syntax like programmer and Linux systems administrator, and you were tasked with creating some simple automation tasks on Windows (monitoring of back-up files, process monitoring, ...). Which language would you prefer to write your scripts in? There's a large collection of VBS-scripts out there (using VB syntax), but I'd prefer anything more C-related. What are your best experiences in using scripts for Windows? Any obvious down- or upside to a certain language? 回答1: I

unable to set variable in case statement bash

佐手、 提交于 2019-12-31 00:10:35
问题 I'm trying to set a variable based on a bunch of input conditions. Here's a small sample of the code: #!/bin/bash INSTANCE_SIZE="" case "$1" in "micro") $INSTANCE_SIZE="t1.micro" ;; "small") $INSTANCE_SIZE="m1.small" ;; esac echo $INSTANCE_SIZE When I run the script with the -ex switch and specify the proper argument: + case "$1" in + =m1.small ./provision: line 19: =m1.small: command not found 回答1: You need to remove the $ sign in the assignments - INSTANCE_SIZE="m1.small" . With the dollar

How To Automate A Telnet Session Without SendKeys

五迷三道 提交于 2019-12-30 18:50:30
问题 I would like to telnet into my router, and I want to automate it so I do not have to login all the time, as I do it several times a day. Is there another method apart from sendkeys in VBS? This is because that physically types, so the telnet window needs to be active, with is rather annoying. I tried a batch file, but I am getting really strange results. Here it is: telnet 192.168.1.254 REM This is the router IP ping 255.255.255.255 -n 1 -w 1000 > nul REM This is to wait for the router if its

Packing Python files into a single .py script

独自空忆成欢 提交于 2019-12-30 18:31:31
问题 Does anybody know if there is any tool for packing a Python project that uses several files and modules into a single script? 回答1: Save this as python_header.py : #!/bin/env/python # -*- coding: ascii -*- import os import sys import imp import tarfile import tempfile RUN_MODULE = "__run__" SENTINEL = 'RzlBTXhya3ljIzl6PFFkQiRKLntEdHF+c2hvWid0IX5NVlxWd' \ 'FxcJ0NWQ2xKVUI0TVEuNl0rWUtnKiRr'.decode('base64') class FileOffset(object): def __init__(self, fileobj, offset=0): self._fileobj = fileobj

Add members dynamically to a class using Lua + SWIG

我的未来我决定 提交于 2019-12-30 11:35:46
问题 This Lua code, creates a table and dynamically adds a new member. Running this I can get "hello" on the screen as expected: foo = {} foo.x = "hello" print(foo.x) But now I'm using SWIG to bind some C++ classes to Lua. For that purpose, in a test.i (SWIG module file) I created a simple class like this: %module test %inline %{ class Foo { public: Foo() { X = 0; } void SetX(int x) { X = x; } int GetX() { return X; } private: int X; }; %} Then I wrote a test Lua code like that: obj = test.Foo()