Visit The New, Modern Unix Linux Community


When I run the code yesterday I am getting output,when I run same code today I am getting error?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers When I run the code yesterday I am getting output,when I run same code today I am getting error?
# 1  
When I run the code yesterday I am getting output,when I run same code today I am getting error?

If run the below code today its creating all directory and getting output files,I f run same code tomorrow I am getting error.
can any one give suggestion to sortout this error.

Code:
OSError:[ERRor 2] no such file or directory : '062518'

My code looks like this

Code:
import paramiko
import sys 
import os 
from datetime import datetime
import time
list_of_hosts = {"10.200.3.444": ["command1","command2"]}   
lis_of_dirs = ["/ooo/SSS/SSSS/data/Capture/AA/","/ooo/SSS/SSSS/data/Capture/BB/"]
for host in list_of_hosts:
ssh = paramiko.SSHClient()  
ssh.load_system_host_keys()  
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())  
ssh.connect('%s' % host,username='xxxxx',key_filename='path')
ssh_con = ssh.invoke_shell() 
print("SSH connection to %s established" % host)
commands = list_of_hosts[host]  

for command in commands:
    stdin, stdout, stderr = ssh.exec_command(command)
    time.sleep(10)
    console_output = (stdout.read())

    print("\n Console OutPut:", console_output)

    for dirs in lis_of_dirs:
        os.chdir(dirs)
        date_dir = datetime.today().strftime('%d%m%y')
        if os.path.isdir(host):
            if os.path.isdir(date_dir):
                os.chdir(date_dir)
                with open(command, 'w') as f:
                    f.write(console_output)
            else:
                os.chdir(host)
                os.chdir(date_dir)
                with open(command, 'w') as f:
                    f.write(console_output)

        else:
            os.makedirs(host)
            os.chdir(host)
            os.makedirs(date_dir)
            os.chdir(date_dir)
            with open(command, 'w') as f:
                 ssh.close()

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!
Please post in an adequate forum!

Last edited by RudiC; 06-25-2018 at 03:42 PM.. Reason: Added CODE tags; moved from "How to Post in the The UNIX and Linux Forums"
# 2  
Hey - where did you buy your crystal ball? I really would like to know in advance when my code is going to work, and when it will fail.


Does that directory 062518 exist?
And, are you sure the error message comes from above code snippet? 062518 does not correspond to the strftime format string %d%m%y . . .

Last edited by RudiC; 06-25-2018 at 03:52 PM..
# 3  
Not exist... Error says no such file or directory
# 4  
So - create it and it will run.
# 5  
Code:
Strftime('%m%d%y')

I am giving like this
When I am trying to create date folder getting error.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 06-25-2018 at 04:28 PM.. Reason: Added CODE tags.
# 6  
Quote:
Originally Posted by haribabu2229
Strftime('%m%d%y')
I am giving like this
Not in above code snippet. On top, watch your syntax.

Quote:
When I am trying to create date folder getting error.
Pls check the entire path for existence and permissions.
# 7  
Hi haribabu2229...

Satisfy my curiosity, I am assuming this is Python 3.x.x code.
if it is then how did you get this section to work at all without a major traceback error?
Code:
for host in list_of_hosts:
ssh = paramiko.SSHClient()  
ssh.load_system_host_keys()  
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())  
ssh.connect('%s' % host,username='xxxxx',key_filename='path')
ssh_con = ssh.invoke_shell() 
print("SSH connection to %s established" % host)
commands = list_of_hosts[host]


Last edited by wisecracker; 06-26-2018 at 01:54 PM..

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #267
Difficulty: Easy
In 1935, at the age of 22, Alan Turning was elected a fellow of King's on the strength of a dissertation in which he proved the central limit theorem.
True or False?

10 More Discussions You Might Find Interesting

1. OS X (Apple)

If you run macOS High Sierra version 10.13.1, be sure to install today's update.

Some hackers found a security hole in macOS High Sierra and tweeted it to the world before telling Apple about the problem. You can see the details from PC Magazine's daily news here: Apple Releases Fix for MacOS High Sierra 'Root' Bug. The original story this morning was published before a patch... (6 Replies)
Discussion started by: Don Cragun
6 Replies

2. Shell Programming and Scripting

Bash code will not run

Why doesn't the code below run? Am I missing something? Thank you :). syntax() { printf "\n\n" printf "Enter HGVS description of variant(s): "; IFS="," read -a hgvs && printf "\n Nothijng entered. Leaving match function." && sleep 2 && return for ((i=0;... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

How to run a script, but not let user see code?

Hi, I want to deploy a (perl) script, in Linux. (Red Hat 7). Is there a way to protect the script itself from being viewed by the user, but still allow the user to run the script? I dont want the user to be able to see the source code of the script. (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies

4. Shell Programming and Scripting

Who -u gives different output if run from cron than if run from terminal?

If I run 'who -u' interactively or from a script invoked through bash in a tty on my Ubuntu 12LTS box I get an output like this: testuser pts/0 Dec 9 02:32 . 2163 (host.xx.yy) running the same through cron I get: testuser pts/0 2012-12-09 02:32 00:05 2163... (2 Replies)
Discussion started by: latimer
2 Replies

5. UNIX for Advanced & Expert Users

[SOLVED] Code does not run when assigned to a variable

I am more of a newbie, but wanted to post this in this forum as I was afraid no one would look at it in unix forums as it concerns shell scripting. I have a shell script that now runs fine with the exclusion of one line: x=`su nbadmin -c "ssh -t servery /usr/openv/netbackup/bin/bplist -C... (7 Replies)
Discussion started by: newbie2010
7 Replies

6. Shell Programming and Scripting

Code to search for a phrase and run a command

hi All, Am newbie to unix and would require your help to complete this task. Condition: I have a server start up script and I would like to append the code in such a way that it searches for a phrase "process completed" in taillog when server starts up and also should run another script... (9 Replies)
Discussion started by: fop4658
9 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Why code run not correctly

Hi there can anyone help me here is my code echo "Type in a positive number" read X I=2 while do if then echo "It is not prime" break else if then echo "It is prime" break else I=$(( $I + 1)) fi fi (4 Replies)
Discussion started by: FUTURE_EINSTEIN
4 Replies

8. Shell Programming and Scripting

HOW to run a bash-code in a c-shell script ??

Is there a way to run some code in a C-shell script by different shell, like bash? I have that situation. I have prepared and perfectly workable bash-skript that now I have to execute under C-shell script, divide it on steps and without creating a new files (with the bash-code parts.) For... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. UNIX for Dummies Questions & Answers

Compile & Run Java Code

The java program is a part of speech tagger -> The Stanford NLP (Natural Language Processing) Group The goal is to use this script as part of a webpage to tag parts of speech based on a user-inputted string. I have no idea what to do with the files - I'm a complete *nix noob. I tried running... (4 Replies)
Discussion started by: tguillea
4 Replies

10. Shell Programming and Scripting

How to run perl code within a shell script...?

Hi, I have a sheel script that invokes a perl script...Now, instead havin the perl script as a separate file I'd like put the contents in the sheel script itself...But I am not sure how ro run that perl script contents.please help me Thanks (1 Reply)
Discussion started by: vijay_0209
1 Replies

Featured Tech Videos