1

I can't seem to figure this one out but when I do a very simple test to localhost to have fabric execute this command run('history'), the resulting output on the command line is blank.

Nor will this work either: run('history > history_dump.log')

Here is the complete FabFile script below, obviously I'm missing something here.

-- FabFile.py

    from fabric.api import run, env, hosts, roles, parallel, cd, task, settings, execute
    from fabric.operations import local,put

    deploymentType = "LOCAL"

    if (deploymentType == "LOCAL"):
        env.roledefs = {       
            'initial': ['127.0.0.1'],
            'webservers': ['127.0.0.1'],
            'dbservers' : ['127.0.0.1']
        }

    env.use_ssh_config = False

    # Get History
    # -------------------------------------------------------------------------------------
    @task        
    @roles('initial')    
    def showHistoryCommands():
         print("Logging into %s and accessing the command history " % env.host_string)
         run('history') #does not display anything
         run('history > history_dump.log') #does not write anything out

         print "Completed displaying the command history"

Any suggestions/solutions would be most welcomed.

1 Answer 1

3

History is a shell builtin, so it doesn't work like a normal command. I think your best bet would be to try and read the history file from the filesystem.

local('cat ~/.bash_history')
       or
run('cat ~/.bash_history')

Substitute for the appropriate history file path.

To expand a bit after some research, the command succeeds when run, but for some reason, be it that fabric neither captures or prints the output. Or the way history prints it's output. While other builtins commands like env work fine. So for now I don't know what exactly is going on.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks xmonk, never occurred to me to look at some of these 'commands' as just shell builtins before. I'll give this a try and report my findings...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.